UIViewController init vs initWithNibName:bundle:

Fr4*_*cis 5 init uitableview uiviewcontroller ios

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

PreferencesController *pController = [[PreferencesController alloc] init];
Run Code Online (Sandbox Code Playgroud)

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

PreferencesController *pController = [[PreferencesController alloc] initWithNibName:@"PreferencesController" bundle:nil];
Run Code Online (Sandbox Code Playgroud)

但我真的不明白它为什么会起作用,因为从文档来看,init似乎足以加载相关的nib文件(PreferencesController.xib).

Ton*_*ony 4

这个名字似乎有某种神奇的东西PreferencesController。我刚刚遇到了完全相同的问题。将我的类(和 xib)重命名为其他名称解决了问题。