29

I have a tabBar + NavigationViewController. The Tab bar has collection view with cells(Say view1) and with cells a push seague is implemented to another view(Say view2).

In view2 I want to have a navBar but no tab bar.

I tried

self.tabBarController?.tabBar.hidden = true,

it worked fine for view2 but when I went back to view1 by back button the tab was still hidden( even after in view1 class I added self.tabBarController?.tabBar.hidden = false in viewDidLoad func).

How can i make the tab bar reappear in view1?

I'm working in swift.

Dharmesh Kheni
  • 71,228
  • 33
  • 160
  • 165

7 Answers7

48

enter image description here

Make sure to check this option only on the ViewController whose tab bar you wish to be hidden.

Thanks to iHarshil for the suggestion.

  • 2
    Great! Nice & easy. Make sure to check this option only on the ViewController whose tab bar you wish to be hidden. Thanks :) – iHarshil Apr 04 '19 at 11:53
44

In the viewDidload set the UIViewController hidesBottomBarWhenPushed to yes:

self.hidesBottomBarWhenPushed = YES;

This way the UINavigationController takes care of hiding the tab bar.

rckoenes
  • 69,092
  • 8
  • 134
  • 166
  • 1
    I had already added this in code in "View2" class fun viewDidLoad but its not working...is there any other way – Siddharth Somvanshi Nov 06 '14 at 13:52
  • 1
    sorry..the code was written in View2 so it was not working...Now i shifted the code to view1 class and the tab gets hidden in View2 but again when i go back to view1 it doesn't get displayed.. – Siddharth Somvanshi Nov 06 '14 at 13:54
  • This hides TabBar forever even after popped back to the root of navigation controller stack. – Bigair Feb 23 '20 at 11:12
  • 1
    Don't added it to the ViewController1. Or you will get this hidden forever. When you instantiate ViewController2, you do it there, before you push it. ``` let vc2 = ViewController2() vc2.hidesBottomBarWhenPushed = true navigationController?.pushViewController(vc2, animated: true) ``` Then when you pop back to V1 it will reappear. – erickva Oct 02 '21 at 12:40
27

Use in prepareForSegue:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"showRecipeDetail"]) {
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
        RecipeDetailViewController *destViewController = segue.destinationViewController;
        destViewController.recipeName = [recipes objectAtIndex:indexPath.row];

        // Hide bottom tab bar in the detail view
        destViewController.hidesBottomBarWhenPushed = YES;
    }
}
shim
  • 9,289
  • 12
  • 69
  • 108
Bruno
  • 1,592
  • 13
  • 14
25

Bruno Fernandes's answer in Swift:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "YourSegueIdentifier" {
        let destinationController = segue.destinationViewController as! YourViewController
        destinationController.hidesBottomBarWhenPushed = true
    }
}

This was the answer that worked for me. Putting hidesBottomBarWhenPushed in the viewDidLoad method didn't work.

Thanks Bruno!

Mr Stanev
  • 1,662
  • 1
  • 19
  • 26
14

In my case, I use hidesBottomBarWhenPushed before I push the destination view controller.

func showSecondViewController() {
  let vc = SecondViewController()
  vc.hidesBottomBarWhenPushed = true
  self.navigationController?.pushViewController(vc, animated: true)
}
Reza Dehnavi
  • 2,256
  • 3
  • 16
  • 30
4

You have to work with viewWillAppear or viewDidAppear. viewDidLoad will be called when view1 is loading (showing) the first time. If you move from view1 to view2 and back the viewDidLoad won't be called again. Therefore you have to use viewWillAppear or viewDidAppear like

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    self.tabBarController?.tabBar.hidden = false
}

Put this code in your view1 controller. The viewWillAppear or viewDidAppear will be called every time navigating back to view1

andre_hold
  • 562
  • 8
  • 20
3

if you want to hide TabBarController Bottom Bar : #Swift 3

In YourViewController : in ViewDidLoad() method

self.tabBarController?.tabBar.isHidden = false
Kiran Jadhav
  • 3,209
  • 26
  • 29