3

I've a problem with something that seems to be very simple. My app has a view hierarchy consisting in a UITabBarController containing UINavigationControllers. When I navigate from the root to the second level I set the hidesBottomBarWhenPushed on true so that the tab bar is hidden

On my firstLevelController:

[secondLevelController setHidesBottomBarWhenPushed:YES];

[self.navigationController pushViewController:secondLevelController animated:YES];

After that when I push to the third level, I bring the tab bar again by doing in the secondLevelController:

[self setHidesBottomBarWhenPushed:NO];

[thirdLevelController setHidesBottomBarWhenPushed:NO];

[self.navigationController pushViewController:thirdLevelController animated:YES];

(I know, I didn't like the [self setHidesBottomBarWhenPushed:NO] either, but it didn´t work otherwise...)

So, here is the problem: when I push the back button in the third level and the second view appears, I need to hide the tabbar again but I couldn´t find the way of doing this.

Any help is appreciated

yuji
  • 16,695
  • 4
  • 63
  • 64
Nicolas
  • 33
  • 1
  • 6
  • 3
    I don't think this is a supported use case. It makes little sense to have the tab bar reappear deeper in the stack hierarchy. You may want to reconsider your design. – Johan Kool Apr 06 '11 at 17:25

5 Answers5

12

This is what works for me.

[self setHidesBottomBarWhenPushed:NO];
[thirdLevelController setHidesBottomBarWhenPushed:NO];
[self.navigationController pushViewController:thirdLevelController animated:YES];
[self setHidesBottomBarWhenPushed:YES];

The thirdlevelController shows the tabbar and secondLevelController does not show the tabbar when you pop the thirdLevelController.

mick80234
  • 897
  • 8
  • 9
  • It is easiest to set it from the target view controller and improves compartmentalization. viewDidLoad can often be too late, so I set it from init or by overriding hidesBottomBarWhenPushed and returning YES or NO. – Peter DeWeese Dec 28 '11 at 14:29
  • 1
    Thank u so much dude!!! i wasted many an hour solving this problem...couldn't have done without it... :D :D – Nishant Sep 05 '12 at 17:08
5

On your secondViewController, do :

- (BOOL) hidesBottomBarWhenPushed {
    return ([self.navigationController.viewControllers lastObject] == self);
}

This way, the tabbar will always be hidden when you are on the secondViewController, and it will appear on the other view controllers

Talal MAZROUI
  • 645
  • 1
  • 6
  • 12
  • This works well when you need to have the tab bar disappear and reappear later in the navigation stack. Thanks! – jbolter Jul 13 '16 at 21:14
0

I was actually on the same problem. I always tried to hide the tabbar when selecting a row and to disable hiding after returning to the list (a tableview inside a navigationcontroller) so that the user can select the menu again. I set the tabbarcontroller hidden inside the method

-(void)tableView:(UITableView *)tableView 
           didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

but when I hided it inside this method, the Tabbar was still hided when returning to my list again. Now I hide the Tabbarcontroller inside the init method of a specific viewcontroller, maybe this works for somebody else too:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {
        // Custom initialization
    }

    [self setHidesBottomBarWhenPushed:YES];

    return self;
}

now when i select a list item and this viewcontroller will be presented the tabbar is hided, after returning to the list it appears again.

Alex Cio
  • 6,014
  • 5
  • 44
  • 74
0

You can hold a bool value to understand if you are coming from a popViewController and in viewDidAppear you can detect it an hide your tab bar again.

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    if(backFromThirdView)
     [self setHidesBottomBarWhenPushed:YES];
    else
         [self setHidesBottomBarWhenPushed:YES];

}

gurkan
  • 3,457
  • 4
  • 25
  • 38
-1

You can try this

You declare in the secondLevelController

static BOOL bottomBarShouldHide = YES;

In the viewDidLoad,

if (bottomBarShouldHide) {
    [secondLevelController setHidesBottomBarWhenPushed:YES];
    bottomBarShouldHide = NO;
}
else {
     [secondLevelController setHidesBottomBarWhenPushed:NO];
     bottomBarShouldHide = YES;
}

I hope it could help you.

William A
  • 121
  • 5