20

I have the following setup:

A tab bar app. On one tab there is a navigation controller.

My workflow:

When I push a new viewController onto the navigation controller stack, I set the hidesBottomBarWhenPushed property.

This works great, the tab bar is "pushed" as the new view controller slides in place.

The problem:

When I pop this view controller and the root view controller is once again displayed, however, the tab bar is gone.

The navigation controller has grown to fill the space left by tab bar.

Is there a property I need to set to make the tab bar visible again?


What I have tried:

popping to the root view manually

setting (resetting) the hidesBottomBarWhenPushed for the root view

resizing the root view

resizing the view property of the navigation controller (just leaves a "white space" where the tab bat should be)

What "sorta" worked:

If I set the selected index of the tab bar controller to any other index, the tab bar appears. So I know it is still "around", but this does little to help me.

Corey Floyd
  • 25,929
  • 31
  • 126
  • 154

10 Answers10

119

I had this problem too. I was setting -hidesBottomBarWhenPushed on the wrong view controller.

Wrong (but seems to work until you pop):

self.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:self.anotherViewController animated:animated];

Right:

self.anotherViewController.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:self.anotherViewController animated:animated];
Dave Batton
  • 8,795
  • 1
  • 46
  • 50
9

this is the same problem i had, but i got a solution, try this I found that hiding and then showing the tabbar immediately after the push, solves our problem

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
 NSDictionary *theItem = [items objectAtIndex:indexPath.row];
 DetailController *nextController = [[DetailController alloc] initWithItem:theItem];
 self.hidesBottomBarWhenPushed = YES;
 [self.navigationController pushViewController:nextController animated:YES];
 //
 //[nextController setHidesBottomBarWhenPushed:YES];
 self.hidesBottomBarWhenPushed=NO;

 [nextController release];

}

eddy
  • 1
  • 1
  • 3
6

If you're using a UINavigationController and looking for a way to just hide the TabBar (BottomBar) in one view controller, place this code in the view controller you'd like to the hide the TabBar for:

- (BOOL)hidesBottomBarWhenPushed {

    return [self.navigationController.visibleViewController isEqual:self]; 
}

Other approaches I tried with just setting the property caused the TabBar to be hidden after pushing a new view controller from the view controller with the hidden TabBar (even after setting the property to NO).

brynbodayle
  • 6,546
  • 2
  • 33
  • 49
1

I do something similar in my app - just calling:

[self.navigationController popToRootViewControllerAnimated:YES];

seems to do the trick and the tab bar is back - admittedly this is in response to a button press rather than the nav bar pop button. I seem to remember it worked fine when using the nav bar back button as well.

Perhaps check you are only setting a single view controller to have the hidesBottomBarWhenPushed property set to YES.

Grouchal
  • 9,756
  • 6
  • 34
  • 46
  • Unfortunately this does not work. It doesn't matter how I pop to the rootView, the Tab bar is still missing. I have set the hidesBottomBarWhenPushed properly for each view controller. – Corey Floyd Jun 24 '09 at 21:20
  • Why have you set it for each viewController? this is why you won't see it when you pop! You need to only set it for the viewController that you want to hide the tab bar! – Grouchal Jun 25 '09 at 06:12
  • I meant that I have explicitly set it to YES or NO depending upon the viewController/situation. Not that I have set them all to NO or YES arbitrarily. – Corey Floyd Jun 30 '09 at 09:45
1

Curious, I never set this value, but override it on the ViewController I want:

- (BOOL) hidesBottomBarWhenPushed
{
    return YES;
}
Thomas Decaux
  • 21,738
  • 2
  • 113
  • 124
1

swift:

self.hidesBottomBarWhenPushed = true
self.performSegueWithIdentifier("viewcontroller_details", sender: nil)
self.hidesBottomBarWhenPushed = false
William Hu
  • 15,423
  • 11
  • 100
  • 121
1

In addition to doing this:

[self.navigationController popToRootViewControllerAnimated:YES];

Initially when you do self.hidesBottomBarWhenPushed = YES;

You have to change for viewControllerToBePushed.hidesBottomBarWhenPushed = YES;

That should do the work!

DaveShaw
  • 52,123
  • 16
  • 112
  • 141
oderfla
  • 19
  • 1
0

In the view controller that appears after the one with the toolbar is popped, try this magic:

- (void)viewWillAppear:(BOOL)animated {
    [self.navigationController setToolbarHidden:YES animated:YES];
}
malhal
  • 26,330
  • 7
  • 115
  • 133
0

Swift 3: From code, you have to set pushedController.hidesBottomBarWhenPushed to true.

Storyboard: Select the pushed controller, go to Attribute Inspector, select "Hide Bottom Bar on Push" option under View Controller.

Bilal Ahmad
  • 187
  • 1
  • 12
0

I had the same issue and I couldn't fix it with any of the suggested approaches mentioned here.

I came up with a hacky way around this problem and it works fine, although in my case MAYBE because I am working with RxSwift, the issue appears to be a race-condition so I slightly delay the pop action and reveal the tabBar manually, nevertheless it might fix your problem as well:

if self.tabBarController?.tabBar.isHidden == true {
    self.tabBarController?.tabBar.isHidden = false

    DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
        self.navigationController?.popViewController(animated: true)
    }
} else {
    self.navigationController?.popViewController(animated: true)
}
Shahriyar
  • 520
  • 7
  • 18