简体   繁体   English

在应用程序的所有视图控制器上显示选项卡栏

[英]Show tab bar on all view controllers of application

I have a problem, I have 2 view controllers on the tab bar controllers. 我有一个问题,我在标签栏控制器上有2个视图控制器。 Both these controllers are showing tabs. 这两个控制器都显示标签。 But when I made a push segue from View controller 1 to View controller 3. View controller 3 do not show the tab bar. 但是当我从View控制器1到View控制器3进行推送时,视图控制器3没有显示标签栏。

I want to show tab on all the controllers of my application. 我想在我的应用程序的所有控制器上显示选项卡。 我的情况

Change your Storyboard Design: 更改故事板设计:

  • set TabBar View Controller as initial ViewController 将TabBar View Controller设置为初始ViewController

  • set your UINavigationViewController as root view controller for each Tab 将UINavigationViewController设置为每个Tab的根视图控制器

  • After all, your Design structure will look like mention Image 毕竟,您的设计结构看起来像提到Image

在此输入图像描述

Your problem exist because your UITabViewController is embedded in the navigation stack that you initialize as a initial controller. 您的问题存在是因为您的UITabViewController嵌入在初始化为初始控制器的导航堆栈中。

You must re-build things so that your tab bar controller tabs opens to a new navigation stack. 您必须重新构建内容,以便标签栏控制器选项卡打开到新的导航堆栈。

  • Remove the first UINavigationController , you don't need it ( if you want it don't use a push segue, use a modal segue, and you won't then be referring back to that UINavigationController 's viewController stack from inside your UITabViewController 删除第一个UINavigationController ,你不需要它(如果你不想使用push segue,请使用模态segue,然后你就不会从UITabViewController里面回到那个UINavigationController的viewController堆栈了。
  • Embed each of the first UIViewControllers in your UITabViewController inside a separate UINavigationController . UITabViewController每个第一个UIViewControllers嵌入到单独的UINavigationController

Now you can push segue within your UITabViewController's tabs 现在,您可以在UITabViewController's选项卡中推送segue

You should realize your struct of views. 你应该意识到你的观点结构。

Now, you have a NavigationController first, and its rootViewController is a Tab BarController. 现在,您首先拥有一个NavigationController,其rootViewController是一个Tab BarController。

NavigationController[0] = TabBarController

and your TabBarController has 2 ViewController( Controller 1 and Controller 2 ) 你的TabBarController有2个ViewController(控制器1和控制器2)

NavigationController[0] = TabBarController

then it includes 2 controllers like 然后它包括2个控制器

TabBarController[0] = Controller 1

TabBarController[1] = Controller 2

when you call 你打电话时

self.navigationController.pushViewController

it means the NavigationController push to Controller 3, so controller 3 will not show tab bar because it is not in TabBarController. 这意味着NavigationController推送到Controller 3,因此控制器3不会显示标签栏,因为它不在TabBarController中。

if you wanna push to controller 3 and still has tab bar, you can insert a container in Controller 1 ( or insert a View ), and create a NavigationController like this 如果你想推送到控制器3并且仍然有标签栏,你可以在Controller 1中插入一个容器(或插入一个View),并创建一个这样的NavigationController

let nav = NavigationController(rootViewController: yourController1)
self.yourViewInsertedInController1.addSubview(nav.view)

then in yourController1 run 然后在yourController1中运行

self.navigationController.pushViewController

it will be right. 这是对的。

To add the view controller to the tab bar controller's array of view controllers, drag from the tab bar controller to that view controller, holding down the Control key. 要将视图控制器添加到选项卡栏控制器的视图控制器阵列,请从标签栏控制器拖动到该视图控制器,同时按住Control键。 Select Relationship Segue > view controllers from the menu that appears. 从出现的菜单中选择Relationship Segue> view controllers。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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