iPhone SDK v2.1 gotcha.

The easiest way to load a NIB containing some element of your user interface on the iPhone is to call the UIKit addition to NSBundle loadNibNamed:owner:options:.

So throughout my code I have the following:

NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MyNIBFile" owner:self options:nil];
UIViewController *c = [nib objectAtIndex:1];

Um, there’s a problem here. On return the NSArray returned contains at index offset 0 a reference to the bundle; the first defined object is at 1 and so forth.

That is, on the iPhone 2.0 SDK.

Using the iPhone 2.1 SDK, the index starts at 0; a reference to the bundle is not returned. Thus, you need to change the statement above to:

UIViewController *c = [nib objectAtIndex:0];


Naturally, of course, if I had used the iPhone SDK like the MacOS SDK, I would have set the file owner in the NIB to an object which contains IBOutlets for the items in the NIB being loaded. And had I done this, I wouldn’t have had a problem at all.

1 thought on “iPhone SDK v2.1 gotcha.

  1. Pingback: iPhone SDK v2.1 gotcha.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s