Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 07-03-2009, 01:31 PM   #1 (permalink)
rhimbo
New Member
 
Join Date: Apr 2009
Location: Los Angeles
Posts: 20
Default How NOT to use nib when initializing a UIViewController subclass?

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,
rhimbo is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 158,805
Threads: 89,205
Posts: 380,611
Top Poster: BrianSlick (7,129)
Welcome to our newest member, chloecoburn
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:13 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.