Note that there are some explanatory texts on larger screens.

plurals
  1. POConfusion about initWithNibName and loadView
    primarykey
    data
    text
    <p>Is the <em>initWithNibName</em> always called whenever programmatically or IB?</p> <p>Example:</p> <p>I have two viewController, one named PhotoViewController, the other named ViewController. The PhotoViewController creates view programmatically, but with initWithNibName uncommented.</p> <p>Here is my PhotoViewController.m:</p> <pre><code>- (void)loadView { NSLog(@"loadView in PhotoView"); UIView *view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame]; [view setBackgroundColor:[UIColor redColor]]; self.view = view; [view release]; } // Loading views from a nib file. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { NSLog(@"PhotoViewController initWithNibName=%@",nibNameOrNil); self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } </code></pre> <p>Here is my call in ViewController.m</p> <pre><code>- (void) doSearchFlickr { PhotoViewController *pController = [[PhotoViewController alloc]init]; [self.view addSubview:pController.view]; [pController release]; } </code></pre> <p>Then I see something confusing me in the log:</p> <pre><code>2011-10-23 10:52:52.151 TableViewPG[1192:b303] PhotoViewController initWithNibName=(null) 2011-10-23 10:52:52.153 TableViewPG[1192:b303] loadView in PhotoView </code></pre> <p>According to the ViewControllerPGforiPhoneOS on page 30, if I override loadView programmatically, initWithNibName should not be called.</p> <p>Is there any flaw(s) in my logic? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload