带有NavigationController和TabController的情节提要 [英] Storyboard with NavigationController and TabController

查看:113
本文介绍了带有NavigationController和TabController的情节提要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎应该很容易弄清楚,但是今天下午我没有任何运气.我将这个问题的快速,简化的情节提要模型放在一起.

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的内部,而UINavigationController置于UITabBarController的内部.这样,您仍然会获得导航栏,并保持在Apple的设计准则之内(您也不会收到那些讨厌的警告,如果您尝试将UITabBarController以外的其他方式安装为UITabBarController,则Apple现在可能会抛出异常.窗口的根视图).

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 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 UITabBarController as anything other than the root view of the window).

这篇关于带有NavigationController和TabController的情节提要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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