I am building a large hierarchical iPhone application with multiple screens controlled by a UINavigationController. One of these screens is able to display content in two different formats (I toggle between them using an IB-created UITabBar), and I have constructed this screen with a view that adds a subview (loaded from a nib file) based on the active tab.
Each of these subviews contains a search bar that needs to push the navigation bar out of the way when it is tapped. The navigation bar is only accessible from the subviews' superview's controller, so I have added a forward declaration of the superview's controller class to the controller of each subview. When a subview is loaded, its "superViewController" property is set.
Typically, each search bar would automatically hide the navigation bar as necessary, but I need to implement this functionality myself because the bar is in the view above the search bars. I have tried doing this by using
[self.superViewController hideNavBar];
in the
- (void)searchDisplayController:(UISearchDisplayController *)controller willShowSearchResultsTableView:(UITableView *)tableView
method, where "hideNavBar" is defined as follows in superViewController.m:
-(void)hideNavBar {
[self.navigationController setNavigationBarHidden:TRUE animated:TRUE];
}
and I have also tried hiding the bar directly with
[self.superViewController.navigationController setNavigationBarHidden:TRUE animated:TRUE];
In both cases, the bar did not change in any way. Do I have to tell the navigation bar to update somehow? Is there a better way to implement the functionality I want?
I know that the forward declaration is working properly because I can push a new view onto the navigationViewController using
NewViewController *newViewController = [[NewViewController alloc] initWithNibName:@"NewView" bundle:nil];
[self.superViewController.navigationController pushViewController:newViewController animated:YES];
[newViewController release];
Thanks in advance, Julian Ceipek
In case it matters, the navigation bar is set to be translucent so that the subviews are underneath the bar.