Whenever a user begins editing a UISearchDisplayController
\'s search bar, the search controller becomes active and hides the view\'s navigation bar while presen
Since iOS 8.0 the same behavior can be achieved by setting the UISearchController
's self.searchController.hidesNavigationBarDuringPresentation
property to false.
The code in Swift looks like this:
searchController.hidesNavigationBarDuringPresentation = false
As jrc pointed out "unhook UISearchDisplayController from controlling any UISearchBar" seems to work for me. If I pass nil as a parameter when creating UISearchDisplayController the navigation bar stays visible at all times:
searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:nil contentsController:self];
Really nice solution, but it was crashing my app under iOS6. I had to make the following modification to get it work.
@implementation ICSearchDisplayController
- (void)setActive:(BOOL)visible animated:(BOOL)animated
{
if (visible == YES) {
[super setActive:visible animated:animated];
[self.searchContentsController.navigationController setNavigationBarHidden:NO animated:NO];
} else {
[super setActive:NO animated:NO];
}
}
@Pavel's works perfectly well. However, I was trying to get this into a UIPopoverController and the text in the field gets pushed slightly when the search bar's text field becomes the first responder, and that looks a bit ugly, so I fixed it by calling the super
method with
animated
set to NO
.
I was adding custom navigation bar on my ViewController which was getting hidden on search, a quick but not so good fix was
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
[self.view addSubview:_navBar];
}
_navBar is UINavigationBar added programmatically, doing this helped me navigation bar from hiding.
The new UISearchController
class introduced with iOS 8 has a property hidesNavigationBarDuringPresentation
which you can set to false if you want to keep the navigation bar visible (by default it will still be hidden).