The default init
method signature on XCode-generated view controllers is:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ }
I've seen these initialized with both values supplied, just the nib name (with bundle as nil), or just nil
as both. All seem to work.
How does the UIViewController really handle self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
? Is there a disadvantage to just passing in nil
for both values?
If you pass nil
as the nibName, the method will look for a nib with the same filename as your view controller.
For instance, if you have a view controller called MyViewController
it will look for a MyViewController.xib
nib file.
If no nib is found, you will need to override the loadView
method to create and assign a UIView to the controller's view outlet.
- (void)loadView
{
UIView *theView = [[UIView alloc] ...
// Setup the main view
self.view = theView;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With