Pregunta

For the impatient:

I want to have a navigationcontroller who's root viewcontroller is a tabbarcontroller, similar to the iPad application. I am using IOS 5 and Storyboards.

For the reading inclined:

In my storyboard I have 6 tabs in a UITabBarController that is embeded in a UINavigationController, giving it a "More" button after 3 tabs are shown.

doing so gives me two navigation bars when more is pressed:

double nav bar... what does it mean?!

So I subclass TabBarController:

//@implentation MyTabController

- (void)viewDidLoad
{
    self.moreNavigationController.wantsFullScreenLayout = NO;
    self.delegate = self;
}

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    // hide nav bar if current controller is "More" controller
    self.navigationController.navigationBarHidden = 
       viewController == self.moreNavigationController;
}

Great, this gives me:

almost there

My guess was that i needed to relayout the views to account for the statusbar, so i try

[self.view setNeedsLayout:YES];

but i get an error saying UIView does not contain a selector for setNeedsLayout so... How do I get the moreNavigationController.navigationBar to account for the statusbar?

Update:
I have a second related issue with this. When I hit the "Edit" button the edit controller shows modally. Its navigationbar displays underneath the insured controller (after an animation), and does not receive touches.

¿Fue útil?

Solución

Pushing a tabBarController into a NavController isn't recommended, instead set a NavigatorController for every tabBar View controller, and set the TabBarController as the main window root view controller.

If you want to be able to show a screen before showing the tabbar, a solution is to push in all the navigator controllers the previous view controller, followed by the one you want to show (that way all navbars has the backbutton). Then set hidesBottomBarWhenPushed = YES to the first view controller, that way it won't show the tabBar.

Example Code:

UIViewController *prevc = [[UIViewController alloc] init];
//prevc.hidesBottomBarWhenPushed = YES;

//Do this for every VC that will be a tabBarItem
UIViewController *vc1 = [[UIViewController alloc] init];
UINavigationController *nv1 = [[UINavigationController alloc] initWithRootViewController:prevc];
[nv1 pushViewController:vc1 animated:NO];

//Remember to set the tabBarItem!

UITabBarController *tb = [[UITabBarController alloc] init];
tb.viewControllers = [NSArray arrayWithObjects:nv1, nv2, nv3, nil];

I just realized that setting hidesBottomBarWhenPushed to the previous ViewController won't work well, but If you show prevc first, and then push the following viewController, you won't have problems. But if anyway you wan't to hide the tab bar while doing a pop, please check this:

Otros consejos

I have also faced a similar problem. In my application also, there is a Tabarcontroller inside a Navigation controller. When i try to switch to a view controller in more navigation controller programatically (like : [self.tabBarController setSelectedIndex:X]; ) the same issues appears in my application. But the following code solves my problem.

    self.tabBarController.moreNavigationController.navigationBarHidden = YES;
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top