Saturday, November 28, 2009

Terminating app due to uncaught exception 'NSInternalInconsistencyException'

One reason for getting this exception may be due to a typo in the name of the NIB file used to init an object.

In my case I was loading a view controller like so:

YellowViewController *yellowController = [[YellowViewController alloc] initWithNibName:@"YellowViev" bundle:nil];

whilst my bundle contained an YellowView.xib. I was using an "v" instead "w" in my NIB name.

So, yeah, check the names. XCode is pretty forgiving (and misleading) here. It would instantiate an object (from an non-existent NIB), in my case a view controller with a view member set to nil. Perhaps a better approach would be to return nil instead a half-baked, incorrect object. Instead it set me to a wild goose chase, to check the view outlet in the NIB and the ensuing scratching of the head.

The error message before the crash wasn't too helpful either:

ViewSwitcher[30112:20b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController loadView] loaded the "YellowViev" nib but no view was set.'

No comments: