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

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

问题描述

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

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

UINavigationControllerHomeViewController 作为根.HomeViewController 有一个 Show (e.g. Push) 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 中没有导航栏.但我认为如果我 Show (e.g. Push) UITabBarController 那么它应该有嵌入式导航控制器,它是故事板中的初始控制器.我对吗?如果是这样,我该如何在 Storyboard 中设置导航栏,因为我在 Storyboard 上看到的推送标签栏中现在有默认栏事件.我已选择 UIViewController 并将身份检查器中的模拟指标设置为 Top 属性的半透明导航栏,但我认为它应该自动添加到此控制器和选项卡栏,无需额外步骤.

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)

回答您的问题:

标签栏控制器界面的每个标签都与一个自定义(不同 [原文如此])视图控制器相关联.当用户选择特定选项卡时,选项卡栏控制器会显示相应视图控制器的根视图,替换之前的所有视图.

所以选项卡的根视图控制器必须与导航控制器相邻;导航视图控制器必须是下一个内联的,以便视图控制器继承导航.Tab Bar 将视图切换到下一个内联的视图.

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天全站免登陆