UIKit:视图控制器自动加载 nib 文件
似乎从最近开始,视图控制器会自动加载一个具有确切名称的 nib 文件(如果存在)。
我可以简单地初始化一个视图控制器
[[[ViewController alloc] init] autorelease]
,然后将其推到导航控制器上时,笔尖就会加载,而无需我做任何事情。
除了一个视图控制器之外,这在我的应用程序中有效,我无法弄清楚为什么。所有自动加载笔尖的视图控制器可能都是在 Xcode 4 中创建的,而唯一一个不起作用的视图控制器可能是在 Xcode 3 中创建的。是否有隐藏的开关?我在笔尖的文件设置、笔尖本身中找不到任何内容,在视图控制器的源代码中也找不到任何可以解释它的内容。
It seems like since recent times, view controllers automatically load a nib file with the exact name if one exists.
I can simply initialize a view controller like
[[[ViewController alloc] init] autorelease]
and then when pushing it onto a navigation controller or so, the nib gets loaded without me ever doing anything.
This works in my app except for one view controller and I fail to figure out why. All view controllers that do load their nibs automatically have probably been created in Xcode 4, while the only one where it doesn't work was propably created back in Xcode 3. Is there a hidden switch somewhere? I coulud not find anything in the file settings of the nib, the nib itself and nothing in the source code of the view controllers that could explain it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
另一件事是,如果您想自动加载 nib 文件,则不应覆盖 UIViewController。
The other thing is, you should not override the UIViewController if you want to load the nib file automatically.
iOS 有区分大小写的文件系统,因此请确保大小写匹配。
仔细检查您正在构建的目标是否已启用笔尖。
检查您是否没有
loadView
方法。检查
nibName
属性的默认处理。iOS has a case-sensitive filesystem, so make sure the case matches.
Double-check that the nib is enabled for the target you are building.
Check you don't have a
loadView
method.Check the default handling for the
nibName
property.另请检查您调用
init
的自定义类是否未实现init
来执行除使用nil
调用自身之外的其他操作笔尖名称。Also check to see if the custom class you are calling
init
on does not implementinit
to do something other than calling itself with anil
nibName.