简体   繁体   中英

Add UINavigationController to UITabBarController without Tab Bar showing up in all views

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:

故事板与流程

Example of desired navigation

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

在此输入图像描述

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

在此输入图像描述

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

在此输入图像描述

Un-suggested solution

在此输入图像描述

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

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.

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM