UIViewController init vs initWithNibName:bundle:

init, ios, uitableview, uiviewcontroller

Solution

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.

Problem

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]; ``` 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]; ``` 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).

Original source