I came across this while solving a slightly different problem. When using UISearchDisplayController, I want the search bar to be in the navigation bar (not below).
It’s not difficult to place the search bar in the navigation bar (see UISearchBar and UINavigationItem ). However, UISearchDisplayController assumes that the search bar is always below the navigation bar and (as discussed here) insists on hiding the navigation bar when entering the search, so everything looks awful. In addition, the UISearchDisplayController displays a search bar that is lighter than usual.
I have found a solution. The trick is to (counter-intuitively) undo the UISearchDisplayController from controlling any UISearchBar at all. If you use xibs, this means deleting the search string instance, or at least disconnecting the output. Then create your own UISearchBar:
- (void)viewDidLoad { [super viewDidLoad]; UISearchBar *searchBar = [[[UISearchBar alloc] init] autorelease]; [searchBar sizeToFit];
You will need to manually activate the search display controller when the user deletes the search bar (in -searchBarShouldBeginEditing: and manually drops the search bar when the user finishes the search (in -searchDisplayControllerWillEndSearch: .
jrc Dec 21 '11 at 23:13 2011-12-21 23:13
source share