Hi folks,
I wrote a UIViewController sub-class that builds its view "manually". That is, I
do not use a nib file created in IB to build the view. That is, I
think I'm not using the nib. I suspect there is something I don't understand about the initialization process....
I have a nib file in my project because I created one and used it before. Now that I coded up the controller's view by hand I am initializing my view controller as follows, passing "nil" to both parameters in my call to -initWithNibName:bundle: (presumably
not using the nib):
Code:
- (id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
self.title = @"View controller title";
NSBundle *bundle = [NSBundle mainBundle];
NSString *legalDisclaimerFilePath = [bundle pathForResource:@"disclaimer" ofType:@"txt"];
NSString *disclaimerText = [NSString stringWithContentsOfFile:legalDisclaimerFilePath];
UIScreen *screen = [UIScreen mainScreen];
CGRect applicationFrame = screen.applicationFrame;
...
// rest of view definition code goes here.
}
}
I call this code with the following statement:
Code:
UIViewController *legalNoticeViewController = [[LegalNoticeViewController alloc] initWithNibName:nil bundle:nil];
I'm passing "nil" to both parameters. So why is my nib file still being executed and loaded? On screen in the simulator I see the visual elements defined in both the nib file
and in the code above that I construct programmatically.
Previously I was using the nib file via the following call:
Code:
UIViewController *legalNoticeViewController = [[LegalNoticeViewController alloc] initWithNibName:@"LegalNoticeViewController" bundle:nil];
But I am
no longer using this call, instead using the one above it where I pass "nil". I did a "clean all" in my project. Is there some remnant binary with which my project is still being linked?
I suspect I don't understand something fundamental to the whole UIViewController initialization process. Could someone explain what happens in the UIViewController class in regards to how -init, -initWithNibName:bundle: gets called? I think that might be the problem and I don't understand the initialization sequence.
Many thanks,