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:
How can I fix this?
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