看起来这应该很容易弄清楚,但我今天下午没有运气.我将我的问题的这个快速、简化的故事板模型拼凑在一起.
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 not have the tab bar visible, and would only be reachable from back buttons on the nav bars of the table view controllers.
我尝试了几种不同的嵌入到 tabbarcontrollers 的方法,但都没有产生预期的结果:
I've tried a few different ways of embedding into a tabbarcontrollers but none of them produce the desired result:
-我尝试选择两个表视图控制器并将它们嵌入选项卡视图控制器中.模拟器中标签栏不显示,出现无法到达的场景"警告.
-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.
-我已经尝试将初始导航控制器嵌入到 tabbarcontroller 中.这将为第一个菜单"页面创建一个选项卡条目.一旦我将表格视图连接到选项卡视图,它也会导致推送问题.
-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.
我会很好地在故事板之上实现一些程序化选项,我只是为这个项目选择了故事板,因为它是一种相对简单的数据呈现方式.
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!
标签栏控制器需要成为视图层次结构的根视图控制器.将标签栏控制器放在任何其他类型的容器控制器中,这违反了 HIG 和 Apple 的标准.
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.
来自 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.
因此,最重要的是您需要重新考虑您的设计.一种选择是将 UITabBarController
设置为窗口的根视图,然后将每个 UITableViewController
放在 UINavigationController
中,它位于 UITabBarController
内.通过这种方式,您仍然可以获得导航栏,并且符合 Apple 的设计准则(您也不会收到那些讨厌的警告,如果您尝试安装 UITabBarController
作为窗口的根视图以外的任何东西).
So, the bottom line here is you need to rethink your design. One option would be to set the UITabBarController
as the root view of your window, and then have each of your UITableViewController
s 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 UITabBarController
as anything other than the root view of the window).
这篇关于带有 NavigationController 和 TabController 的情节提要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!