I have a UIViewController
with the navigation bar HIDDEN
, a couple of buttons up top, and UITableView
with a UISearchController
as a header.
Here is the issue: when I create the UISearchController
, I also have this line:
self.definesPresentationContext = YES;
Now what happens is that when I search using the UISearchController
, and click on one of the results in the UITableView
, it opens my following UIViewController
(which is exactly what it is supposed to do -- and the following UIViewController
also has the navigation bar hidden) correctly but it displays a grayish navigation bar at the top of the UIViewController
, even though I'm setting the navigation bar as hidden.
Now when I set:
self.definesPresentationContext = NO;
The navigation bar does not appear in the following view but instead of that, the UISearchController's SearchBar
appears in the following UIViewController
at the same place as it was in the main view controller, even though it's obviously not supposed to be there anymore.
This is what it's supposed to look like (top of the UIViewController):
This is what happens when `self.definesPresentationContext = YES;
And this is what happens when `self.definesPresentationContext = NO;
How can I get back to situation number one? UPDATE Here is a sample project that duplicates this issue: http://www.filedropper.com/sampleprojectbugreport
It does look like a bug in iOS. If you're not planning on showing the navigation bar at all, you could subclass UINavigationController
and override the -setNavigationBarHidden:animated:
method and hard-code the hidden
value:
-(void)setNavigationBarHidden:(BOOL)hidden animated:(BOOL)animated {
[super setNavigationBarHidden:YES animated:animated];
}
I've tested this workaround and it prevents the navigation bar from showing.
See updated sample project: http://appsandwich.com/stackoverflow/navcontrollersubclass.zip