简体   繁体   中英

Hiding a superview controller's UINavigatonBar from within a subview's controller?

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.

Have you tried using a modal view controller? Based on each selection, if you push a modal view controller onto the view it will automatically hide the navigation bar.

http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html

Essentially it is meant to be a screen that is used to temporarily accept user data. If you implement this it will automatically hide the navigation bar when it comes into view as it is owned by the view controller that presents it and is not pushed onto the navigation controller stack.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM