Crashing when pushing a XIB based view controller onto navigation controller stack

Posted by Michael on Stack Overflow See other posts from Stack Overflow or by Michael
Published on 2010-04-23T21:02:32Z Indexed on 2010/04/23 21:03 UTC
Read the original article Hit count: 336

Filed under:

I was attempting to clean up the implementation for a sub-panel on a navigation controller stack, so that the navigation bar could be customized in the XIB instead of doing it manually in the viewDidLoad method.

The original (working) setup had the XIB set up with the "File's Owner" class set to the view controller class, and then the view at the top level. This works fine.

In the "Interface Builder User Guide", p. 71, it describes the recommended way to build the XIBs for sub-panels ("additional navigation levels"). This approach leaves the "File's Owner" class as NSObject, but adds a UIViewController at the top level, and nests the view (and navigation item) underneath it. The UIViewController's view automatically gets connected to the contained view.

When I try to push the controller init'd with this new XIB, the app crashes because of a missing view: SettingsViewController *controller = [[SettingsViewController alloc] initWithNibName:@"SettingsView" bundle:nil];

[self.navigationController pushViewController:controller animated:YES];

2010-04-23 11:17:37.135 xxxx[1173:207] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "SettingsTestView" nib but the view outlet was not set.'

I've double checked everything, and tried building a clean XIB from scratch, but get the same result.

I looked through a number of the code sample projects, and NONE of them use the documented/recommended approach--they all use the File's Owner class and manually set up the navigation bar in viewDidLoad like I originally had it.

Is it possible to get it working the "recommended" way?

Thanks!

Michael

© Stack Overflow or respective owner

Related posts about iphone-sdk