3

I am learning UISearchController by following this tutorial. However, the UISearchBar is not shown. This is my code:

let searchController = UISearchController(searchResultsController: nil)
override func viewDidLoad() {
    super.viewDidLoad()
    searchController.searchResultsUpdater = self
    searchController.obscuresBackgroundDuringPresentation = false
    searchController.searchBar.placeholder = "Search Candies"
    navigationItem.searchController = searchController
    definesPresentationContext = true
}

And this is how my app looks like:

enter image description here

How can I fix this?

1 Answer 1

17

If you scroll down the table view the search bar will appear but you can set the hidesSearchBarWhenScrolling property to false so the search bar remains, as the documentation says, regardless of the current scroll position.

navigationItem.hidesSearchBarWhenScrolling = false
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.