Reputation: 490
I am using a UISearchController inside a Container view in a UITableView. I am adding the search bar like this:
self.resultsTableController = [self.storyboard instantiateViewControllerWithIdentifier:NSStringFromClass([ResultViewController class])];
self.searchController = [[UISearchController alloc] initWithSearchResultsController:self.resultsTableController];
self.searchController.searchBar.frame = CGRectMake(self.searchController.searchBar.frame.origin.x, self.searchController.searchBar.frame.origin.y, self.searchController.searchBar.frame.size.width, 44.0);
self.searchController.searchResultsUpdater = self;
[self.searchController.searchBar sizeToFit];
self.searchController.hidesNavigationBarDuringPresentation = NO;
self.tableView.tableHeaderView = self.searchController.searchBar;
self.resultsTableController.tableView.delegate = self;
self.searchController.delegate = self;
self.searchController.dimsBackgroundDuringPresentation = YES;
self.searchController.searchBar.delegate = self;
self.definesPresentationContext = NO;
See the following screenshots. It hides all the search results that are above the search bar:
Please help me out why i am getting this?
Upvotes: 7
Views: 452
Reputation:
I found searchcontroller is little tricky. I had lot of issues and I found that specific order matters. The following combination is what worked for me
searchController.searchResultsUpdater = self
searchController.searchBar.delegate = self
searchController.dimsBackgroundDuringPresentation = false
searchController.searchBar.placeholder = "search"
searchController.searchBar.returnKeyType = .done
searchController.searchBar.searchBarStyle = .minimal
searchController.hidesNavigationBarDuringPresentation = false
searchController.searchBar.sizeToFit()
definesPresentationContext = true
if(tableView.tableHeaderView == nil){
tableView.tableHeaderView = searchController.searchBar
}
You can have
searchController.hidesNavigationBarDuringPresentation = false
Upvotes: 1