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!
 

 

3 Responses to “iPhone + Interface Builder”

  1. iPhone Development - First Impressions « The Pages o’ Peat Says:

    [...] iPhone.  Can someone point me at an example? I found a step-by-step example here and posted my own followup summary for people who are already familiar with Interface Builder, and just want to see how to plug in [...]

  2. Jason Hullinger Says:

    I’ve built a few “Hello World” applications for the iPhone, but I’ve yet to see Interface Builder actually working correctly. You can build your interface with no problem, but hooking in actions to events does not yet seem to be supported. Have you found this to be true, or have I totally missed something?

  3. Peat Says:

    @jason - The example Apple provides that I’ve linked to at the top of the post shows off the basics — connecting actions and events and whatnot. It’s still a little rough around the edges (as of Beta 3), but it works!

    Beta 4 is out. I haven’t had any time to play with it, though!

Leave a Reply