How no make a button show UINavigationBar only in 3 of 5 tabs in UITabBar?
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 UIIma开发者_StackOverflow社区geView, 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?
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];
}
That was easier than I thought. I just have to put
- (void)viewDidAppear:(BOOL)animated {
[self.navigationController setNavigationBarHidden:YES animated:NO];
[super viewDidAppear:animated];
}
精彩评论