Note: The Pages o’ Peat have moved to http://peat.org/ — please update your bookmarks and references accordingly. Thank you!

Note: This is a little out of date, since the Beta 3 build automatically generates an empty XIB and the code for including it in new projects. If you’re looking for Apple’s introductory tutorial on how to build applications with Interface Builder, click here.

So, the trick to using Interface Builder is figuring out where to put the files, and plugging the XIB interface into the app.

The file question is easily answered:  File > Write Class Files to the directory in your project where the rest of your classes live.  For really simple apps with a single view, select your existing AppDelegate class and IB will merge the changes for you. You’ll also see a new .xib file in your classes directory, containing your interface.

Connecting the XIB interface is also relatively straight forward.  In your AppDelegate file, change what self.contentView points at:

self.contentView = [[[NSBundle mainBundle] loadNibNamed:@"XIBFileName" owner:self options:nil] objectAtIndex:0];

Where XIBFileName is the name of the generated XIB file without the .xib extension.

Anyhow. I’m still learning, and this is with a beta release of the iPhone SDK, so you’re welcome to leave comments if you have better ideas or tips on working with IB for the iPhone. Thanks!
 

 

Advertisements