05.01.2013 Views

Mac OS X Leopard - ARCAism

Mac OS X Leopard - ARCAism

Mac OS X Leopard - ARCAism

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Figure 25-9. Editing a user interface in Interface Builder<br />

The Interface<br />

CHAPTER 25 MAC <strong>OS</strong> X DEVELOPMENT: THE TOOLS 459<br />

The nib is your interface, so it should come as no surprise that your interface elements are at the<br />

center of the nib’s contents. When you open your nib in Interface Builder for the first time, you’re<br />

greeted with the same document window you saw when building and running your nascent<br />

application. The window you see in the nib is the same window the user will be greeted with, but<br />

editable.<br />

Double-click the words “Your document contents here” to edit the text field. Type the new<br />

text, “Hello World!” in its place. Since many interface elements have dynamic content that is difficult<br />

to render in edit mode, you can simulate your interface in normal mode by selecting<br />

Simulate Interface from the File menu, or by typing Cmd+R.<br />

This launches your interface in Cocoa Simulator. You can interact with your interface to<br />

make sure it does what you expect when, for example, resizing a window. Resizing the window<br />

in Cocoa Simulator reveals an unexpected problem. The text area seems to be anchored to the<br />

bottom-left corner of the window, rather than doing what we would expect, which is to stay centered.<br />

We’ll fix that in moment. For now, quit Cocoa Simulator by selecting Quit from the file<br />

menu or typing Cmd+Q.<br />

Testing the interface by itself is OK for some tasks, but it doesn’t show how the interface<br />

works with your application. For more complicated testing, you’ll want to actually build and run<br />

your application. There are a few ways to do this. You can save your interface, and then quit<br />

Interface Builder, or switch back to Xcode to build and run, as we did before.<br />

You can also build and run in Xcode from within Interface Builder itself. Save your interface<br />

by selecting Save from the File menu, or typing Cmd+S. Then select Build and Go in Xcode from<br />

the File menu, or type Shift+Cmd+R. This will send a message to Xcode (no doubt using Apple-<br />

Script) to build and run your application, just like you did earlier.<br />

You should see your document window with your new text. You should also notice we still<br />

have that resizing bug. Quit your application in the usual way and return to Interface Builder.<br />

Select the text area with a single click. It’s time to meet the Inspector.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!