AlexBains
AlexBains

Reputation: 295

UISearchController not Shown

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?

Upvotes: 3

Views: 2848

Answers (1)

Francesco Deliro
Francesco Deliro

Reputation: 3939

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

Upvotes: 17

Related Questions