I'm trying to set up a UISearchController
with a custom UITableViewController
for the results. In my main UITableViewController
I have a segue from my main UITableViewController
to a detail controller, if I pass in a model object to the detail controller with values the search bar is initially hidden but if I scroll it displays (similar to when loading the Inbox in the default iOS mail app). If no values are passed to the results controller then the search bar is displayed.
I am creating the search results controller in the detail view controller as follows:
func configureSearchController() {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
guard let resultsController = storyboard.instantiateViewController(withIdentifier: "resultsController") as? SearchResultsTableViewController else {
return
}
self.searchController = UISearchController(searchResultsController: resultsController)
// results controller handles search results
searchController.searchResultsUpdater = resultsController
searchController.searchBar.delegate = resultsController
searchController.searchBar.placeholder = "Search items"
searchController.searchBar.returnKeyType = .done
searchController.searchBar.sizeToFit()
searchController.edgesForExtendedLayout = []
self.definesPresentationContext = true
self.navigationItem.searchController = searchController
}
This is what happens:
How can I make it so the search bar always shows on the detail controller?