iOS 9 searchBar disappears from table header view when UISearchController is active

Solution 1:

I'm not sure what exactly is the problem but I 'fixed' it by:

self.searchController.hidesNavigationBarDuringPresentation = NO;
self.definesPresentationContext = NO;

My guess is that UISearchController is doing something funky when it is trying to present as a navigation bar. So, this is a hack but it at least doesn't block the user. The search bar doesn't do the cool animation and cover up the navigation bar.

Solution 2:

It seems all of us got the same problem but they were solved in different ways. However none of the suggested answers worked for me :(. Nevertheless thank you all for your time.

I got a solution that solved my problem. It is setting Extend Edges - Under Opaque Bars of my (MyModalView: UITableViewController) to true in the Storyboard using Interface Builder.

In summary:

MyModalView: UITableViewController, in Storyboard using Interface Builder has

Extend Edges: - Under Top Bars ticked - Under Bottom Bars ticked - Under Opaque Bars ticked

screenshot

Solution 3:

I found it's the simulated metrics (top bar) in storyboard that's cause this problem. In my case, the following lines work, but I still don't know why.

- (void)willPresentSearchController:(UISearchController *)searchController {
    // do something before the search controller is presented
    self.navigationController.navigationBar.translucent = YES;
}

-(void)willDismissSearchController:(UISearchController *)searchController
{
    self.navigationController.navigationBar.translucent = NO;
}

Solution 4:

I had to

self.aNavigationController?.extendedLayoutIncludesOpaqueBars = true

I found a similar question here but in my case it was not on the viewDidLoad method. I had to try different views until it worked. Now I can have both a custom navigation bar color and the search bar,