views:

80

answers:

2

In trying to debug why a view controller is initing empty, I've ended up a sort of weird place. Check this out:

OffersSearchController *searchController = [[OffersSearchController alloc]
        initWithNibName:@"This is a completely bogus nib name."
             bundle:nil];

Not a single complaint. I've seen that sort of construct crash out with complaints about being unable to find a nib named "This is a completely bogus...", but not this time. Instead, my searchController pushes onto the navigation controller as if it had loaded successfully. It's empty, though--I can see the full screen of another view that's (accidentally!) "underneath" my UINavigationController stack.

What's happening here? Is [OffersSearchController alloc] coming back nil for some reason?

EDIT: Never mind. Here's the lesson: don't implement loadView when you mean to implement viewDidLoad. Oy. Long week.

A: 

The documentation for UIViewController initWithNibName:bundle doesn't say anything about what happens if the specified nib name is invalid. Presumably then, an invalid nib name is treated the same as a nil one. However, it does say that the return value is always an initialized UIViewController.

So, what that code is doing is to allocate/initialize a new OffersSearchController with no nib. The view appears empty because it is. You've probably never actually seen that crash before, because it's not supposed to; what's happening is perfectly normal.

alexantd
If u specify an invalid nib name, the app will crash actually
Daniel
"Presumably then, an invalid nib name is treated the same as a nil one." You know what they say about presuming, right?
Dan Ray
+1  A: 

Here's the answer (thanks @Eric Petroelje for suggesting I post and accept the answer).

In a burst of late-Friday-afternoon productivity, moving far faster than is recommended, I set up my property initializers and picker-wheel-data-source arrays in -(void)loadView rather than in -(void)viewDidLoad.

Rather than the initWithNibName: call's call to loadView being allowed to propagate up to UIViewController, it happily initialized my fields and that's all.

Dan Ray