You can pass any string name to initWithNibName: You are not just limited to calling initWithNibName:@"MyClassName" when your class is called MyClassName . It could be initWithNibName:@"MyClassNameAlternateLayout" .
This becomes useful if you need to load a different icon depending on what the application should do. Although I try to simplify the development and maintenance process as much as possible, I try to use one controller for each controller for each category of devices (iPhone or iPad), I could understand if the developer wants to provide another layout or various functions from time to time.
Another important point: initWithNibName: bundle: is the designated initializer for the UIViewController . When you call -[[UIViewController alloc] init] , then initWithNibName:bundle: -[[UIViewController alloc] init] called backstage. You can check this with a symbolic breakpoint. In other words, if you just want the default behavior, it is expected that you can call -[[UIViewController alloc] init] , and the designated initializer will be invoked implicitly.
If, however, you call -[[UIViewController alloc] init] and donβt get the expected behavior, then probably your subclass of UIViewController incorrectly implemented - (id)init . The implementation should look like one of these two examples:
- (id)init { self = [super init]; if (self) { // custom initialization } return self; }
or
- (id)init { NSString *aNibName = @"WhateverYouWant"; NSBundle *aBundle = [NSBundle mainBundle]; // or whatever bundle you want self = [self initWithNibName:aNibName bundle:aBundle]; if (self) { // custom initialization } return self; }
source share