29

My application is a Tabbed Application, and it have several controllers under the tabBarController. One controller is a navigationController, and its root view is a table view. When I click a row of the table view, another view will be pushed in. So the question is that when the view is pushed in, how can I hide the tabBar at the bottom? Besides, I also want to add another tabBar into the pushed view, so I need to alloc a UITabBar or UITabBarController? Or there is another way? Thank you!

Haroldo Gondim
  • 7,725
  • 9
  • 43
  • 62
wjldxt
  • 345
  • 1
  • 3
  • 5

5 Answers5

67

use this methood in the UIViewController class where you want to hide the tabBarController

-(BOOL)hidesBottomBarWhenPushed
{
    return YES;
}

Update

As suggested by @Yuchen Zhong in his answer, This option is now available in the storyboard itself.

enter image description here

Bonnie
  • 4,943
  • 30
  • 34
  • 1
    Thanks! I used this method but it still did not work. I also used "myViewController.tabBarController.hidesBottomBarWhenPushe = YES", and it didn't work too. I'm confused about this. Do I need to change my structure or there are better ways? Thank you! – wjldxt Jan 03 '12 at 04:58
  • 1
    I have a similar TabBar application with NavigationController as its 1st controller, but in the navigationController I have then only added a tableView, and push the other view's in didSelectRow methood of the table view. have you taken tableVeiwController instead a simple tableView..?? would be helpful if you paste some of your code here – Bonnie Jan 03 '12 at 05:46
  • 1
    Thank you! I did it eventually. It's my own fault that I put the navigationController into a viewController. When I use the navigationController directly, it succeeded. Thank you very much! – wjldxt Jan 03 '12 at 05:59
20

You can do this in storyboard now:

  1. Select the UIViewController in your storyboard
  2. Select the checkbox Hide Bottom Bar on Push

enter image description here

Yuchen
  • 30,852
  • 26
  • 164
  • 234
15

Set UIViewController.hidesBottomBarWhenPushed = YES when you want hide tab bar.

nextViewController.hidesBottomBarWhenPushed = YES;
aturan23
  • 4,798
  • 4
  • 28
  • 52
tuoxie007
  • 1,234
  • 12
  • 10
5

Sometimes the hidesBottomBarWhenPushed method hides the bottom bar with a choppy animation.

Instead I hide the tabbar in viewDidLoad with

self.tabBarController.tabBar.hidden = YES;

and restore its presence in viewWillDisappear

self.tabBarController.tabBar.hidden = NO;
Zack Zhu
  • 378
  • 4
  • 8
  • not nice, as you assume in this VC that another VC on the stack wants the tabbar - also `viewDidLoad` is the wrong location, as it might be called even when this VC does not yet appear, also `self.tabBarController` might be `nil` – fabb Jun 13 '17 at 12:44
1

Set true hidesBottomBarWhenPushed in the controller that you want to hide.

For hide all controllers put into prepare for segue

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    segue.destination.hidesBottomBarWhenPushed = true
}
Haroldo Gondim
  • 7,725
  • 9
  • 43
  • 62