UIViewController init vs initWithNibName:bundle: [英] UIViewController init vs initWithNibName:bundle:

查看:76
本文介绍了UIViewController init vs initWithNibName:bundle:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我正在推动一个视图控制器(一个UITableViewController),它还有一个引用UITableViewCell的属性/出口。看来用以下方法创建控制器:

In my app I am pushing a view controller (a UITableViewController) that has also a property/outlet referencing a UITableViewCell. It appears that creating the controller with:

PreferencesController *pController = [[PreferencesController alloc] init];

不会在xib文件中为UITableViewCell创建对象,因此出口为空,因此表加载会生成异常。
我用以下方法解决了这个问题:

doesn't create the object for the UITableViewCell in the xib file, thus the outlet is null, thus the table loading generates an exception. I solved this with:

PreferencesController *pController = [[PreferencesController alloc] initWithNibName:@"PreferencesController" bundle:nil];

但我真的不知道为什么它有效,因为从文档中看起来init应该足够了加载相关的nib文件(PreferencesController.xib)。

but I didn't really get why it worked, as from documentation it seems that init should be sufficient to load the related nib file (PreferencesController.xib).

推荐答案

似乎有一些神奇的名字 PreferencesController 。我刚才有同样的问题。将我的类(和xib)重命名为其他东西可以解决问题。

There seems to be something magical about the name PreferencesController. I just had the exact same problem. Renaming my class (and xib) to something else solved the problem.

这篇关于UIViewController init vs initWithNibName:bundle:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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