Datasheet

Book VII
Chapter 1
A User Interface
for Adding Hotels
and Using the
Address Book
743
Add AddHotelController
Isn’t it a beauty? Well, okay, the aesthetics do leave a bit to be desired, but
I’ll leave that up to you after I show you how to take care of all the plumbing
you need behind it.
Adding controls to the view
The first pipes you want to lay involve adding controls to the view. Here’s
what you need to do:
1. In the Resources folder (if that’s where you placed it), double-click the
AddHotelController.xib file.
2. Make sure the Library window is open. If it isn’t, open it by choosing
ToolsLibrary or pressing Ô+Shift+L. Make sure Objects is selected in
the mode selector at the top of the Library window and that Library is
selected in the drop-down menu below the mode selector.
To refresh your memory, the Library has all the components you can
use to build a user interface. These include the things you see on the
iPhone screen, such as labels, buttons, and text fields; and those you
need in order to create the “plumbing” to support the views (and your
model), such as the view controllers.
AddHotelController.xib was created by Xcode when I created
AddHotelController.m from the template. As you can see, the file
already contains a view — all I have to do here is add the static text,
images, and text fields. If you drag one of these objects to the View
window, it will create that object when your application is launched.
3. Drag five Label elements from the Library window over to the View
window.
4. Double-click each label and enter the text Name, Address, City State,
and Zip as I have in Figure 1-2.
Labels display static text in the view. (Static text can’t be edited by
the user.)
You may notice a rectangle around the label in Figure 1-2. I’ve turned
on this feature so you can see the labels more clearly. (You can turn
this particular feature on or off by choosing LayoutShow/Hide Bounds
Rectangle.) This rectangle won’t show onscreen when the app is running.
Your View should look something like Figure 1-2 when you’re done.
You’ll also want the labels to be right justified, which is done on the
Attributes Inspector. (See Figure 1-3.) The next step shows you how.
5. Click to select the Label text and then choose ToolsAttributes
Inspector. (Pressing Ô+1 is another way to call up the Attributes
Inspector.) Click the Right Justified icon in the Layout section of the
Inspector, as I have in Figure 1-3.
41_542934-bk07ch01.indd 74341_542934-bk07ch01.indd 743 3/23/10 11:01 PM3/23/10 11:01 PM