UISearchController makes the controller black

ios, ios8, uisearchbar, uisearchcontroller

Solution

Try self.definesPresentationContext = YES; instead of NO. Here is how I setup my UISearchController, but I haven't done it this way in a UITabBarController before.

func setupSearchController() {
    let resultsController = UIStoryboard(name: "ATPageTableViewController", bundle: nil).instantiateViewControllerWithIdentifier("ATPageTableSearchResultsViewController") as! ATPageTableSearchResultsViewController
    searchController = UISearchController(searchResultsController: resultsController)
    searchController.delegate = self
    resultsController.delegate = self
    resultsController.cellIdentifier = ATDataSetItemTableViewCellIdentifier;
    resultsController.table = self.table!
    searchController.searchBar.sizeToFit()
    self.tableView.tableHeaderView = searchController.searchBar
    searchController.searchResultsUpdater = self
    searchController.searchBar.delegate = self
    definesPresentationContext = true

}

Problem

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..

Original source