0

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.

Julian Ceipek
  • 525
  • 3
  • 13
  • and @cone Did you got the answer for your question? How to solve this problem? Can you help me? This is my problem :- http://stackoverflow.com/questions/6381161/how-to-hide-superview-navigationbar-in-subview-in-ipad – Yuvaraj.M Jun 17 '11 at 07:33

1 Answers1

0

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.

cone
  • 1,665
  • 3
  • 13
  • 13
  • I thought about using something like that, but it still wouldn't solve my problem as far as I can tell. I want the navigation bar to remain onscreen so that the user can navigate back through the application. I only want the bar to disappear temporarily, while the user is interacting with the search box or scrolling. I am also hesitant to use a modal view controller based on Apple's guidelines because I need the user to be able to access and modify views lower down in the view hierarchy than the superview I mentioned in my question. – Julian Ceipek Jun 14 '11 at 18:35
  • If you want the navigation bar to remain on the screen, why don't you push a new view onto the navigationController stack? Based on which button is pressed, you can push the corresponding view, and show/hide the navigationBar for that viewcontroller. It's cleaner than attempting to manipulate the superview's navigationBar. – cone Jun 16 '11 at 04:17
  • Thanks! I got it to work using the method described here: http://stackoverflow.com/questions/410471/how-can-i-pop-a-view-from-a-uinavigationcontroller-and-replace-it-with-another-in/1787323#1787323 The only annoying thing about this solution is that it requires a separate tab bar that doesn't switch its selected item on each view. – Julian Ceipek Jun 16 '11 at 15:02