2

I want to show tab bar only on parent controllers not on any of the child.

I'm doing this on push:

childViewController?.hidesBottomBarWhenPushed = true
self.navigationController?.pushViewController(childViewController!, animated: true)

Now, when I navigate back by clicking 'Back' button the bar is shown agin on parent.

But if I do the same programatically like this:

childViewController?.hidesBottomBarWhenPushed = true
self.navigationController?.popToRootViewController(animated: true)
//or
self.navigationController?.popViewController(animated: true)

Then the tab bar is not shown again on parent.

I have already tried many solutions like;

Solution 1: writing this code in child

- (void)viewWillAppear:(BOOL)animated { 
    self.hidesBottomBarWhenPushed = true 
}
- (void)viewWillDisappear:(BOOL)animated {
    self.hidesBottomBarWhenPushed = false 
}

Solution 2: writing this code on push

childViewController?.hidesBottomBarWhenPushed = true
self.navigationController?.pushViewController(childViewController!, animated: true)
childViewController?.hidesBottomBarWhenPushed = false

None of it worked. Everything works well if I navigate back with navigation bar back button. But if I popViewController or popToRootViewController then it doesn't works.

Using: XCode 8.3.2, Swift 3

Please help me out. Thank you in advance.

1 Answers1

0

Use this way in the controller in which you want to hide:

override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
    super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
    self.hidesBottomBarWhenPushed = true
}
nitin.agam
  • 1,354
  • 1
  • 11
  • 19