如何正确实现带导航控制器的标签栏控制器 [英] How to implement tab bar controller with navigation controller in right way

查看:128
本文介绍了如何正确实现带导航控制器的标签栏控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Storyboard和Xcode 6.我的故事板中有下一个控制器和场景:

I am using Storyboard and Xcode 6. I have next controllers and scenes in my Storyboard:

UINavigationController HomeViewController 作为根。 HomeViewController 有一个按钮显示(例如推送) UITabBarController UITabBarController 有4 UIViewControllers

UINavigationController that has HomeViewController as a root. HomeViewController has a button that Show (e.g. Push) UITabBarController. UITabBarController has 4 UIViewControllers.

但我的问题是在我显示 UITabBarController 之后,4 UIViewControllers 中没有导航栏。但我想如果我显示(例如推送) UITabBarController 那么它应该有嵌入式导航控制器,它是初始控制器故事板。我对吗?如果是这样,我怎样才能在Storyboard中设置导航栏,因为我在故事板上看到了推送标签栏中的默认栏事件。我选择了UIViewController并将身份检查器中的模拟指标设置为Top属性的Translucent Navigation bar,但我认为它应该自动添加到此控制器和标签栏而无需额外的步骤。

But my problem that after I Show UITabBarController there are no Navigation Bars in 4 UIViewControllers. But I supposed that if I Show (e.g. Push) UITabBarController then it should has embedded navigation controller that is initial controller in storyboard. Am I right? And if so how can I setup then navigation bar in Storyboard, because there are now default bar event in pushed tab bar that I see on storyboard. I have selected UIViewController and set simulated metrics in identity inspector to Translucent Navigation bar for the Top property, but I supposed it should be automatically added to this controller and to the tab bar without additional steps.

或者我应该为每个具有根视图控制器的标签栏项添加新的导航控制器吗?

Or should I add new navigation controller for each tab bar items that will have their root view controllers?

我看不到导航的主要问题在故事板中使用show(例如Push)。例如,如果我添加导航控制器然后设置为根 - 标签栏控制器,那么Xcode会自动添加顶部导航栏,但如果队列有一个额外的步骤,就像在我的情况下HomeViewController一样,顶部导航栏永远不会自动出现。

The main question why I don't see navigation bar in storyboard using show (e.g. Push). For example if I add navigation controller and then set as root - tab bar controller then Xcode automatically add top navigation bar, but if the queue has an extra step like in my case HomeViewController the top navigation bar never appear automatically.

推荐答案

您需要在自己的导航控制器中嵌入标签栏内的每个视图控制器。所以流程是这样的(HomeVC嵌入在它自己的NavController中):

Hi you need to embed each view controller that is within the tab bar in a navigation controller of its own. So the flow is like so (HomeVC is embedded in a NavController of it's own):

                                         / --> `NavController` --> `ViewController1`
                                         | --> `NavController` --> `ViewController2`
`HomeViewController`-->`TabBarController`|--> `NavController` --> `ViewController3`
                                         \--> `NavController` --> `ViewController4`




  1. 转到编辑器 - - > 嵌入 - > 标签栏控制器(或导航控制器)

  1. Go to Editor --> Embed In --> Tab Bar Controller (or Navigation Controller)

回答您的问题:


标签栏控制器界面的每个标签都与自定义(不同的[sic])视图控制器相关联。当用户选择特定选项卡时,选项卡栏控制器将显示相应视图控制器的根视图,替换以前的任何视图。

因此选项卡的Root View Controller必须与导航控制器相连;导航视图控制器必须是下一个内联,以便View Controller继承导航。选项卡栏将视图切换为下一个内联的内容。

So the Root View Controller of the tab must be adjoined to a Navigation Controller; a navigation view controller must be next inline in order for the View Controller to inherit a Navigation. A Tab Bar switches views to whatever is next inline.

本文档将帮助您概述有关它的更多信息。 https://developer.apple.com/documentation/uikit/uitabbarcontroller

This document will help outline more information about it. https://developer.apple.com/documentation/uikit/uitabbarcontroller

这篇关于如何正确实现带导航控制器的标签栏控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆