3

I currently have Tab Bar Controller with a Navigation Controller, as described here.

As a result, the tab bar shows below each view.

Is there a way to hide the tab bar on consecutive screens, which are not directly connected to the tab bar controller, using Storyboard.

The current flow is pictured here:

storyboard with flow

Example of desired navigation

For example, "Second View" should show with the navigation controller, since it is direct child of Tab Bar Controller.

enter image description here

However, the "Third View" and "Fourth View", should have the navigation controller only (without the tab bar):

enter image description here

Actual (with tab bar) vs. the expected (desired result is the view without the tab bar):

enter image description here

Un-suggested solution

enter image description here

A possible way to get the desired flow is to create a navigation controller then connect it to the Tab Bar Controller. However this is not recommended as a UI pattern by Apple (Apple docs suggest to use the above method), and leads to several subtle bugs:

  • Can no longer rearrange tabs in Tab Bar Controller as they disappear
  • Can't set the Navigation title for "Second View" from Storyboard
  • Editor > Embed in > Navigation Controller is greyed out for the Tab Bar Controller (as it is not a recommended practice), so you have to manually create it
user2560886
  • 1,910
  • 2
  • 14
  • 20

1 Answers1

4

UIViewController has a property hidesBottomBarWhenPushed. Set it to true in viewDidLoad of ThirdViewController and FourthViewController.

UPDATE

Your current hierarchy of view controllers is completely fine. Don't change it to anything else.

UPDATE 2

You're right viewDidLoad is not good enough. Use init?(coder:).

required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
    hidesBottomBarWhenPushed = true
}

Or set a flag in Interface Builder.

enter image description here

Artem Stepanenko
  • 3,423
  • 6
  • 29
  • 51
  • I just tried this, it's a bit buggy. Pushing onto the navigation stack, the bottom bar is still shown on the "third view" but gets successfully hidden on the "fourth view". Popping of the stack, both "third view" and "fourth view" have successfully hidden bottom bars. – user2560886 Jan 13 '17 at 22:45
  • 1
    Ok, it seems like `viewDidLoad` is too late in the view cycle, setting `hidesBottomBarWhenPushed` to `true` in the segue for `ThirdViewController` does the trick. – user2560886 Jan 13 '17 at 22:57
  • 1
    @user2560886 you're right, it seems to be late. I've updated the answer. – Artem Stepanenko Jan 13 '17 at 23:01