I'm trying to figure out why my whole navigation bar disappears when I start typing in the UISearchController.searchBar It loads properly and animates properly, but I lose the active NavBar when I start typing. Here's the code to load the searchController from viewDidLoad:
UITableViewController *searchResultsController = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
searchResultsController.tableView.dataSource = self;
searchResultsController.tableView.delegate = self;
searchResultsController.tableView.backgroundColor = [UIColor redColor];
self.searchController = [[UISearchController alloc] initWithSearchResultsController:searchResultsController];
self.searchController.delegate = self;
self.searchController.searchResultsUpdater = self;
self.searchController.dimsBackgroundDuringPresentation = YES;
self.searchController.hidesNavigationBarDuringPresentation = NO;
[self.searchController.searchBar sizeToFit];
self.tableView.tableHeaderView = self.searchController.searchBar;
self.definesPresentationContext = NO;
And here's the result after I start typing:
Notice how the table view is there, but it appears to occupy the space of the nav controller and extend downwards into the first section heading. Any ideas?
Thanks.
You need to set definesPresentationContext to YES. From apples example:
// Search is now just presenting a view controller. As such, normal view controller
// presentation semantics apply. Namely that presentation will walk up the view controller
// hierarchy until it finds the root view controller or one that defines a presentation context.
self.definesPresentationContext = YES
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