R – UIViewController not working for the first time

initializationiphonenibnulluiviewcontroller

MyController *myViewController = [[MyController alloc] initWithNibName:@"myView" bundle:nil];

The nib file myView.nib has 2 uiimageviews and 2 uilabels. When I first init myViewController, all the 4 subviews are set as 0x0.
The second time I dont get such a behavior.

Best Answer

The view object itself does not get created until it is referenced via self.view and loadView is called. It could be that the first time you try to inspect the view or do something with it this hasn't happened yet, and the second time could be after the system creates the view if you are adding it to another view or a navigation controller or something.