0

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.

5
  • So the TabBarController was pushed into the NavigatorController? If that's the case, that's not recommended, you should set a NavigatorController for every tabBar View controller, and set the TabBarController as the main window root view controller. If that's not the case, I have no idea what's happening :P.
    – JP Illanes
    Jun 14, 2012 at 16:41
  • @Raspu That would solve most of my problems, but what about the back button? since to do it this way I would present the tab bar modally and even if I added a back button to each navigation controller it would not have the <__| shape.
    – Tom Fobear
    Jun 14, 2012 at 17:57
  • So you want to be able to go back to the 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). Alternative you can set the hidesBottomBarWhenPushed = YES to the first view controller, that way it won't show the tabBar.
    – JP Illanes
    Jun 14, 2012 at 18:09
  • @Raspu if you make these comments an answer I will reward you the bounty.
    – Tom Fobear
    Jun 14, 2012 at 19:10
  • Done, glad you found it useful!
    – JP Illanes
    Jun 14, 2012 at 19:38

2 Answers 2

1
+50

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:

5
  • I cannot accept bounty for a few more hours. Just wondering is there a style i can give a uibarbuttonitem to make it look like a back button? I am not having luck with pushing all the view controllers I have everything set up in Storyboard.
    – Tom Fobear
    Jun 14, 2012 at 22:29
  • As far as I know, is not possible to shape it as a back button. But if you have problems setting the previous View Controller maybe you can push a dummy view controller, and then use the UINavigatorBar delegate (Note that I'm talking of the Bar, not the controller), to act when the user press the back button (navigationBar:shouldPopItem:), and change the previous VC to the desired one (I'm not sure if it's possible) as a reference: developer.apple.com/library/ios/#documentation/uikit/reference/…
    – JP Illanes
    Jun 15, 2012 at 2:56
  • And, actually you can change the rightButton shape using a background image (I have done this before, but it was at iOS 3 times, so I'm not sure if still possible).
    – JP Illanes
    Jun 15, 2012 at 2:58
  • I give up on getting the previous nav controller to play nice. I cannot get it to work with my storyboard setup. I removed the segue that goes from previous controller to tabbarcontroller and instantiated the tabbarcontroller by identifier. Then when I was ready for the "segue" I would iterate tabbarcontroller.viewControllers and push them before i push tabbarcontroller itself. I am just going to put a button in each of the tabbarcontroller's viewscontrollers.
    – Tom Fobear
    Jun 15, 2012 at 13:56
  • Let me know if it's working. Sorry anyway, but I have never used storyboard, is kind of "too new" for me.
    – JP Illanes
    Jun 15, 2012 at 14:00
0

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;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.