Datasheet
Book VII
Chapter 1
A User Interface
for Adding Hotels
and Using the
Address Book
749
Making the Connections in Interface Builder
I’ve also had you declare two new methods (and the usual initialization
method), getFromContacts: and saveToContacts:, each with the
keyword IBAction as the return type. IBAction is actually defined as a
void, so if you think about it, all you’ve done is declare a new method with a
return type of void.
- (IBAction)getFromContacts:(id)sender;
is the same as
- (void) getFromContacts:(id)sender;
This simply means that you’ve declared a method that doesn’t return any-
thing when it’s sent a message.
The actual name you give the method can be anything you want, but it must
have a return type of IBAction. Usually the action method takes one argu-
ment — typically defined as id, a pointer to the instance variables of an
object — which is given the name sender. The control that triggers your
action will use the sender argument to pass a reference to itself. So, for
example, if your action method was invoked as the result of a button tap, the
argument sender would contain a reference to the specific button that was
tapped.
A word to the wise — having the sender argument contain a reference
to the specific button that was tapped is a very handy mechanism, even if
you’re not going to take advantage of that in the RoadTrip application. With
that reference in hand, you can access the variables of the control that was
tapped.
But even though all these connects will happen automatically, it won’t auto-
matically happen automatically. You need to do some work back in Interface
Builder first. So put aside Xcode and return to Interface Builder.
Be sure to save AddHotelController.h or you won’t see the outlets or
methods in Interface Builder.
Making the Connections in Interface Builder
In the previous section, I mentioned that if you want to be able to access the
text fields (street, state, zip, name, and city) you’ve set up in RoadTrip,
you had to take two steps:
1. Declare an IBOutlet in your code.
2. Use Interface Builder to point the outlet to the text fields you created
earlier in Interface Builder.
41_542934-bk07ch01.indd 74941_542934-bk07ch01.indd 749 3/23/10 11:01 PM3/23/10 11:01 PM