Or you can use [NSBundle loadNibNamed:owner:options:] method instead of. This method ensures all outlet connections connected. (which [UIViewController initWithNibName: bundle:] doesn't)
Sample code
In this case, File's Owner in the NIB is an external instance of PhotoShow class.
// This works completely. All outlets works.
PhotoShow* obj = [[PhotoShow alloc] init];
[[NSBundle mainBundle] loadNibNamed:@"PhotoShow" owner:obj options:nil];
// Outlets are always available at this moment.
// This works. but does not connects outlets correctly sometimes.
PhooShow* obj = [[PhotoShow alloc] initWithNibName:@"PhotoShow" bundle:[NSBundle mainBundle]];
// Outlets may not available at this moment.
Selection from reference document
You can use this method to load user interfaces and make the objects available to your code. During the loading process, this method unarchives each object, initializes it, sets its properties to their configured values, and reestablishes any connections to other objects. (To establish outlet connections, this method uses the setValue:forKey: method, which may cause the object in the outlet to be retained automatically.) For detailed information about the nib-loading process, see Resource Programming Guide.
answered 2010-01-24T08:12:08.923