xcode 带有 NavigationController 和 TabController 的故事板

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14246454/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 02:29:07  来源:igfitidea点击:

Storyboard with NavigationController and TabController

objective-cxcodeuinavigationcontrolleruitabbarcontrollerstoryboard

提问by mElling

It seems like this should be easy to figure out, but I haven't had any luck this afternoon. I threw together this quick, simplified storyboard mockup of my problem.

看起来这应该很容易弄清楚,但今天下午我没有任何运气。我把我的问题的这个快速、简化的故事板模型放在一起。

Basically, I would like the table view controllers below to also be in a tab bar controller (in addition to the already present navigation controller). The tabs would switch between the two table view controllers.

基本上,我希望下面的表视图控制器也位于选项卡栏控制器中(除了已经存在的导航控制器)。选项卡将在两个表视图控制器之间切换。

Right now, the view controller with the buttons acts as a sort of menu. Each button leads to one of the table view controllers. Ideally this view controller would nothave the tab bar visible, and would only be reachable from back buttons on the nav bars of the table view controllers.

现在,带有按钮的视图控制器充当一种菜单。每个按钮通向表视图控制器之一。理想情况下,此视图控制器不会显示选项卡栏,并且只能通过表视图控制器的导航栏上的后退按钮访问。

I've tried a few different ways of embedding into a tabbarcontrollers but none of them produce the desired result:

我尝试了几种不同的嵌入到 tabbarcontrollers 的方法,但没有一种方法能产生想要的结果:

-I've tried selecting both table view controllers and embedding those in a tab view controller. The tabbar doesnt show up in simulator, and the 'unreachable scene' warning appears.

- 我尝试选择两个表视图控制器并将它们嵌入到选项卡视图控制器中。模拟器中不显示标签栏,并出现“无法访问场景”警告。

-I've tried embedding the initial nav controller into a tabbarcontroller. This creates a tab entry for the first 'menu' page. It also causes issues with push segues once I connect the tableviews to the tabview.

- 我尝试将初始导航控制器嵌入到 tabbarcontroller 中。这将为第一个“菜单”页面创建一个选项卡条目。一旦我将 tableview 连接到 tabview,它也会导致 push segue 出现问题。

I would be fine implementing some programmatic options on top of the storyboard, I just chose storyboarding for this project since it's a relatively simple presentation of data.

我会很好地在故事板之上实施一些编程选项,我只是为这个项目选择了故事板,因为它是一个相对简单的数据展示。

What is the proper way of going about this? Thanks!

解决这个问题的正确方法是什么?谢谢!

Storyboard Screenshot

故事板截图

回答by jmstone617

A tab bar controller needs to be the root view controller of your view hierarchy. It goes against the HIG and Apple's standards to put a tab bar controller inside of any other type of container controller.

标签栏控制器需要是视图层次结构的根视图控制器。将标签栏控制器放在任何其他类型的容器控制器中是违反 HIG 和 Apple 的标准的。

From the Apple docs:

来自苹果文档:

When deploying a tab bar interface, you must install this view as the root of your window. Unlike other view controllers, a tab bar interface should never be installed as a child of another view controller.

部署标签栏界面时,必须将此视图安装为窗口的根目录。与其他视图控制器不同,标签栏界面不应作为另一个视图控制器的子项安装。

So, the bottom line here is you need to rethink your design. One option would be to set the UITabBarControlleras the root view of your window, and then have each of your UITableViewControllers inside of a UINavigationController, which is placed inside of the UITabBarController. In this way, you still get the navigation bar, and stay within Apple's design guidelines (you also won't get those pesky warnings, and Apple may even be throwing an exception nowadays if you try to install a UITabBarControlleras anything other than the root view of the window).

因此,这里的底线是您需要重新考虑您的设计。一种选择是将 设置UITabBarController为窗口的根视图,然后将每个UITableViewControllers 放在 a 中UINavigationController,该s 位于UITabBarController. 通过这种方式,您仍然可以获得导航栏,并保持在 Apple 的设计指南内(您也不会收到那些讨厌的警告,如果您尝试将 a 安装UITabBarController为根视图以外的任何内容,Apple 现在甚至可能会抛出异常窗户)。

回答by Yogesh Lolusare

I accept JMStone answer but we might get into situation where we need to put tab bar controller inside other controller especially table view controller.

我接受 JMStone 答案,但我们可能会遇到需要将标签栏控制器放入其他控制器尤其是表视图控制器的情况。

Please refer Storyboard navigation controller and tab bar controller

请参考Storyboard 导航控制器和标签栏控制器

and also the good example by Matthjin: http://cl.ly/VQLa

以及 Matthjin 的好例子:http://cl.ly/VQLa

Hopes it help some one who want to put tab bar controller inside table view controller and wants proper navigation.

希望它可以帮助那些想要将标签栏控制器放在表格视图控制器中并想要正确导航的人。