通过 UITabBarController 自动从另一个笔尖加载 UINavigationController
我想我已经找到了原因:IB 中的文档信息窗口有一个警告:“‘选定的导航控制器(第二)’的 nib 名称属性设置为‘SecondView.nib’,但此视图控制器并不旨在以这种方式设置其视图。”
真糟糕。
我在 Interface Builder 中构建了 nib,它在顶层具有 UITabBarController
并在 UINavigationController
之间切换。
当所有内容都在单个 nib
文件中时,它工作正常,但我想为 UINavigationController
使用单独的 nib
文件。
从 Apple 的 TabBar 模板开始,如果我只是将 SecondView 的类更改为 UINavigationController
,一切都会中断:
我得到的只是:
// imgur has lost the image, sorry //
是否可以为 UINavigationController
提供单独的文件,而无需以编程方式设置所有内容?
我希望 TabBarController 来处理笔尖的加载和卸载。
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.
I've built nib in Interface Builder that has UITabBarController
at top level and switches between UINavigationController
s.
It works fine when everything is in a single nib
file, but I'd like to use separate nib
files for UINavigationController
s.
Starting with Apple's TabBar template, if I just change class of SecondView to UINavigationController
, it all breaks:
and all I get is this:
// imgur has lost the image, sorry //
Is it possible to have separate file for UINavigationController
without programmatically setting everything?
I would like TabBarController
to handle loading and unloading of nibs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
只需将 UINavigationController 与 FirstViewController 交换即可。
所以层次结构应该是这样的:
您将检查器中第一个视图控制器的 nib 设置为包含实际视图对象的 nib 文件(因为您试图将它们拆分为单独的文件,这是一件好事)。
您有一个选项卡,该选项卡有一个导航控制器,它将加载第一个视图控制器作为其根视图。
完毕。
Simply swap the UINavigationController with the FirstViewController.
So the hierarchy should be like this:
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).
You have one tab, that tab has a navigation controller which loads First View Controller as its root view.
Done.
我还没有尝试通过 IB 设置 UINavigationController。 我有多个屏幕,每个屏幕都存储在单独的 xib 中,并且有一个扩展 UIViewController 的相应类。 在 applicationDidFinishLaunching 中,我使用 xib 初始化 UIViewControllers,但随后手动创建 UINavigationController,将导航控制器的视图添加到窗口并将第一个视图推送到导航控制器。
不确定这是否有帮助。
上面的 FirstViewController 扩展了 UIViewController,在 IB 中,您创建视图,然后将文件的所有者类设置为您的类(例如此处的 FirstViewController),并将文件的所有者视图连接到 UIView 的视图。
I haven't tried setting up UINavigationController via IB. I have multiple screens, each is stored in separate xib and there's a corresponding class that extends UIViewController. In applicationDidFinishLaunching I initialize UIViewControllers using xib's but then manually create UINavigationController, add navigation controller's view to window and push first view to navigation controller.
Not sure if that helps.
Above FirstViewController extends UIViewController, in IB you create your view then set File's owner class to your class (e.g. here FirstViewController) and connect the File's owner view to the UIView's view.
我相信您正在寻找这样的东西。 您可以将“whatever”替换为第二个 nib 文件的名称。
I believe you are looking for something like this. You would replace "whatever" with the name of you second nib file.
首先,看起来您的
UITabBarItem
位于导航控制器下,而不是直接位于UITabBarController
下。 这可能是你问题的一部分。其次,当您在 IB 中添加 UITabBarController 并单击顶级对象列表中的图标(第一个屏幕截图)时,属性检查器将允许您更改视图控制器的类型每个选项卡。 如果您愿意,您可以使用它将它们全部更改为导航控制器。 此外,由于您想从其他 nib 加载自定义视图和视图控制器,因此如果查看属性检查器底部的“视图控制器”部分,您可以从项目中选择一个 nib 来加载视图。 假设 nib 的“文件所有者”设置为您的 UINavigationController 子类,那么它应该可以正常工作。
所有这一切都不需要大量的编码工作。 如果您需要我正在讨论的内容的屏幕截图,请告诉我,以防您找不到这些面板。
First, it looks like you have your
UITabBarItem
s under the navigation controllers instead of directly under theUITabBarController
. That may be part of your problem.Second, when you add a
UITabBarController
in IB and and click on its icon in your list of top-level objects (your first screenshot), the attributes inspector will allow you to change the type of view controller for each of the tabs. Using this, you can change them all to navigation controllers, if you wish. Also, since you wanted to load custom views and view controllers from other nibs, if you look at the "View Controller" section at the bottom of the attributes inspector, you can select a nib from your project to load the view from. Assuming that nib's "File's Owner" is set to yourUINavigationController
subclass, it should all work fine.All of this without a large amount of coding work, either. Let me know if you'd like screenshots for what I'm talking about in case you can't find these panels.
我发现了同样的警告。我将所有视图控制器保存在单独的 xib 文件中。 我通过删除 .nib 名称并将其保留为空来摆脱它。
I found the same warning.I have kept all view controller in separate xib files. I got rid off it by removing .nib name and keeping it empty.