views:

108

answers:

2

I have an app, where there's a UITabBar with 5 tabs. When user shakes the device, I want the UINavigationBar to push an UIImageView. When I show the UIImageView, I need to hide both tab and nav bars. After that, when user taps the UIImageView, the NavBar appears again and user can go to the UIImageView's parent view. I make the Nav Bar appear like this:

[[self navigationController] setNavigationBarHidden:NO animated:YES];

But in two tabs I have to make the Nav Bar appear, so user can switch to UIImageView's parentView and then, when the parent view appears, hide the nav bar. How can I do it?

A: 

I think you should set up a UITabBarController delegate and implement this method:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    // Put real logic here
    BOOL shouldHideNavBar = (viewController == myViewController1 || viewController == myViewController4);
    [[self navigationController] setNavigationBarHidden:shouldHideNavBar animated:YES];
}
Costique
XCode gives out an error "expected expression before myViewController1"
Knodel
I've managed to get rid of the error by creating objects of each UIViewController class and putting them instead of myViewController1 and myViewController4, but it doesn't work. The Nav Bar remains untouched on its place.
Knodel
How to do it best depends on your app's structure. Make sure some object which keeps references to your view controllers is a delegate of the UITabBarController. Then check what is passed as _viewController_ to this delegate method, if it's a navigation controller, replace [self navigationController] with (UINavigationController *) viewController. I cannot verify the exact behavior right now, but this is very likely.
Costique
A: 

That was easier than I thought. I just have to put

  • (void)viewDidAppear:(BOOL)animated { [self.navigationController setNavigationBarHidden:YES animated:NO]; [super viewDidAppear:animated]; }
Knodel