标签栏控制器中每个视图的不同导航项

时间:2023-01-30 17:27:31

The Problem

I'm relatively new to Swift and I'm trying to build an application that makes use of a UITabBarController.

我是Swift的新手,我正在尝试构建一个使用UITabBarController的应用程序。

What I'm trying to do is put a different navigation bar (or UINavigationItem) on each of the tabs in the UITabBarController.

我要做的是在UITabBarController的每个选项卡上放置一个不同的导航栏(或UINavigationItem)。

For example, I want the UINavigationItem I set, with its bar button items, to appear on MyViewController instead of a back button to the previous view controller, such as shown on the image below.

例如,我希望我设置的UINavigationItem及其条形按钮项目显示在MyViewController而不是前一个视图控制器的后退按钮上,如下图所示。

标签栏控制器中每个视图的不同导航项

The current layout on the Storyboard is as follows.

故事板上的当前布局如下。

标签栏控制器中每个视图的不同导航项

MyViewController on the sidebar:

侧栏上的MyViewController:

标签栏控制器中每个视图的不同导航项

What I've Tried

我试过的

Someone suggested that I should embed each UIViewController (e.g. MyViewController) in a Navigation Controller. I've tried this and it doesn't work.

有人建议我应该在导航控制器中嵌入每个UIViewController(例如MyViewController)。我试过这个并没有用。

I've also tried to set the Top Bar to "None" in the Attributes tab of the options menu.

我还尝试在选项菜单的“属性”选项卡中将顶栏设置为“无”。

标签栏控制器中每个视图的不同导航项

Thank you in advance for your help.

预先感谢您的帮助。

1 个解决方案

#1


0  

Here is how i did it,

我是怎么做到的,

UINavigationController -> UITabbarController

UINavigationController - > UITabbarController

And then each "Tab" is in different Storyboard and every storyboard start with a "Navigation Controller". So yes every tab in different navigation controller this how you should do it.

然后每个“Tab”都在不同的Storyboard中,每个故事板都以“导航控制器”开头。所以是的,不同的导航控制器中的每个选项卡都是你应该这样做的。

Different storyboards because may be multiple people work on storyboard at same time.

不同的故事板因为可能是多人同时在故事板上工作。

Why TabbarController inside Navigationcontroller ?

为什么在Navigationcontroller里面有TabbarController?

I put the "TabbarController" inside "NavigationController" because some of the controllers i want them to be full screen, like hiding the "Tabbar" so for that i push them from main NavigationController.

我把“TabbarController”放在“NavigationController”里面,因为有些控制器我希望它们是全屏的,比如隐藏“Tabbar”所以我将它们从主NavigationController中推出。

//Out of context but may help you, I have created an "Extension" of Navigation Controller to push a view controller on main navigation so that any of the tabbars (which are also inside navigation controllers) can easily use the extension to push any view controller if want to hide the tabbar.

//脱离上下文但可能对你有所帮助,我创建了一个导航控制器的“扩展”来推动主导航上的视图控制器,这样任何一个标签栏(也在导航控制器内)都可以轻松地使用扩展来推送任何视图控制器,如果要隐藏标签栏。

#1


0  

Here is how i did it,

我是怎么做到的,

UINavigationController -> UITabbarController

UINavigationController - > UITabbarController

And then each "Tab" is in different Storyboard and every storyboard start with a "Navigation Controller". So yes every tab in different navigation controller this how you should do it.

然后每个“Tab”都在不同的Storyboard中,每个故事板都以“导航控制器”开头。所以是的,不同的导航控制器中的每个选项卡都是你应该这样做的。

Different storyboards because may be multiple people work on storyboard at same time.

不同的故事板因为可能是多人同时在故事板上工作。

Why TabbarController inside Navigationcontroller ?

为什么在Navigationcontroller里面有TabbarController?

I put the "TabbarController" inside "NavigationController" because some of the controllers i want them to be full screen, like hiding the "Tabbar" so for that i push them from main NavigationController.

我把“TabbarController”放在“NavigationController”里面,因为有些控制器我希望它们是全屏的,比如隐藏“Tabbar”所以我将它们从主NavigationController中推出。

//Out of context but may help you, I have created an "Extension" of Navigation Controller to push a view controller on main navigation so that any of the tabbars (which are also inside navigation controllers) can easily use the extension to push any view controller if want to hide the tabbar.

//脱离上下文但可能对你有所帮助,我创建了一个导航控制器的“扩展”来推动主导航上的视图控制器,这样任何一个标签栏(也在导航控制器内)都可以轻松地使用扩展来推送任何视图控制器,如果要隐藏标签栏。