My UITableViewController
is conforming to the new UISearchControllerDelegate
and also UISearchResultsUpdating
.
Here is my setup code for the search bar:
override func viewDidLoad() {
var searchController = UISearchController(searchResultsController: self)
searchController.searchResultsUpdater = self
self.tableView.tableHeaderView = searchController.searchBar
self.definesPresentationContext = true
}
However, when running this in the simulator there is no search bar in the table header, even though it is specified in the code. I also tried this code in viewWillAppear
, but again no search bar was shown.
I was informed by an Apple Engineer that you must give the Search Bar a frame. If you print the frame of the search bar, you will notice it's height is zero. So this is probably a bug in Apple's code.
searchController.searchBar = CGRectMake(0.0, 0.0, 320.0, 44.0)
Edit:
The documentation specifies that you must pass in the View Controller that you want to display the results. To display this in the same View Controller you are in, pass in nil.
var searchController = UISearchController(searchResultsController: nil)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With