问题描述
我想我找到原因:IB中的文档信息窗口有一个警告:所选导航控制器(第二)的nib名称属性设置为SecondView.nib,但此视图控制器
I think I've found the cause: Document Info window in IB has a warning: "'Selected Navigation Controller (Second)' has nib name property set to 'SecondView.nib', but this view controller is not intended to have its view set in this manner."
Bummer。
我在Interface Builder中构建了nib,在顶层有 UITabBarController
,在 UINavigationController
s。
I've built nib in Interface Builder that has UITabBarController
at top level and switches between UINavigationController
s.
当一切都在一个 nib
文件中时,它工作正常,但我想为 UINavigationController
使用单独的 nib
文件。
It works fine when everything is in a single nib
file, but I'd like to use separate nib
files for UINavigationController
s.
从Apple的TabBar模板开始,如果我只是将SecondView的类更改为 UINavigationController
,则所有中断:
Starting with Apple's TabBar template, if I just change class of SecondView to UINavigationController
, it all breaks:
我所得到的是:
// imgur has lost the image, sorry //
是否可以为 UINavigationController
分隔文件,而无需以编程方式设置所有内容?
Is it possible to have separate file for UINavigationController
without programmatically setting everything?
我想要 TabBarController
来处理nib的加载和卸载。
I would like TabBarController
to handle loading and unloading of nibs.
推荐答案
只需将UINavigationController与FirstViewController交换即可。
Simply swap the UINavigationController with the FirstViewController.
所以层次结构应该是这样:
So the hierarchy should be like this:
Tab bar controller
-----Tab bar
-----Navigation Controller
----------First View Controller
---------------Navigation Item
----------Tab bar item (First)
-----Navigation Controller
----------Second View Controller
---------------Navigation Item
----------Tab bar item (Second)
您在检查器中将First View Controller的nib设置为nib文件包含实际的视图对象(因为你试图将它们拆分成单独的文件,这是一件好事)。
You set the nib of First View Controller in the inspector to the nib file containing the actual view objects (Since you are trying to split them into separate files, which is a good thing).
你有一个选项卡,控制器以其根视图加载First View控制器。
You have one tab, that tab has a navigation controller which loads First View Controller as its root view.
完成。
这篇关于通过UITabBarController从另一个nib自动加载UINavigationController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!