I am using UISearchController in iOS 8 with the following intializaiton in viewDidLoad of a view controller embedded in a tab controller
_searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
_searchBar = _searchController.searchBar;
[_searchController.searchBar sizeToFit];
_searchController.searchBar.delegate = self;
_searchController.searchResultsUpdater = self;
_searchController.dimsBackgroundDuringPresentation = NO;
_searchController.hidesNavigationBarDuringPresentation = NO;
self.definesPresentationContext = NO;
_shopsTable.tableHeaderView = _searchController.searchBar;
I've implemented
- (void) updateSearchResultsForSearchController:(UISearchController *)searchController
and (void)filterContentForSearchText:(NSString *)searchText
and the search works, the tableview gets updated properly, etc.
But!
If I switch tabs while the searchcontroller is active (just tapping the search bar or with some text) to a different tab, and then go back to teh search tab, I get a blank screen with only the search bar, like this
In this case, I search for things that start with lar
, which did return results and displayed them correcly. But if I switch tabs, and return to the search tab I get a blank screen like this. The only way the controller returns to its original state is if I do _searchController.active = NO
. But if the user wants to keep that search active, I can't just deactivate it.
I am sure I am missing something, but since there isn't much to do in UISeachController, I can't figure out what is causing this..