Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent a UISearchDisplayController from hiding the navigation bar

Whenever a user begins editing a UISearchDisplayController's search bar, the search controller becomes active and hides the view's navigation bar while presenting the search table view. Is it possible to prevent a UISearchDisplayController from hiding the navigation bar without reimplementing it?

like image 217
hadronzoo Avatar asked May 11 '10 17:05

hadronzoo


People also ask

How do I hide and show navigation bar?

Touch “Settings” -> “Display” -> “Navigation bar” -> “Buttons” -> “Button layout”. Choose the pattern in “Hide navigation bar” -> When the app opens, the navigation bar will be automatically hidden and you can swipe up from the bottom corner of the screen to show it.

How do I hide navigation bar on Iphone?

You can find the Website View menu in what's called the Smart Search field at the top of the Safari interface. Launch the app and navigate to a website, then tap the "aA" icon in the upper left corner of the screen. Simply select Hide Toolbar from the dropdown menu, and the toolbar will shrink to show just the URL.


1 Answers

I just debugged a bit into UISearchDisplayController and found that it's calling a private method on UINavigationController to hide the navigation bar. This happens in -setActive:animated:. If you subclass UISearchDisplayController and overwrite this method with the following code you can prevent the navigationBar from being hidden by faking it to be already hidden.

- (void)setActive:(BOOL)visible animated:(BOOL)animated; {     if(self.active == visible) return;     [self.searchContentsController.navigationController setNavigationBarHidden:YES animated:NO];     [super setActive:visible animated:animated];     [self.searchContentsController.navigationController setNavigationBarHidden:NO animated:NO];     if (visible) {         [self.searchBar becomeFirstResponder];     } else {         [self.searchBar resignFirstResponder];     }    } 

Let me know if this works for you. I also hope this won't break in future iOS versions... Tested on iOS 4.0 only.

like image 195
stigi Avatar answered Sep 24 '22 21:09

stigi