Datasheet
750
Making the Connections in Interface Builder
Similarly, to execute a method in your code when the user taps a button, you
also had to do two things:
1. Declare an IBAction in your code.
2. Use Interface Builder to point the event in the button you created earlier
to the IBAction method in your code.
You’ve created the IBOutlets and the IBAction methods and now I’m
going to show you how to create the connection in Interface Builder so that
when the nib file is loaded, the nib loading code will create these connec-
tions automatically. With these connections established, you’ll be able to
get the data from your text field interface objects and receive messages from
your buttons.
So, it’s connection time.
1. For your RoadTrip project, be sure to add the instance variables and
methods to your code as spelled out in Steps 1 through 10 in the
“Adding controls to the view” section, earlier in this chapter; then
choose File➪Save or press Ô+S to save what you have done for each
file.
You have to save your code; otherwise, Interface Builder won’t be able
to find it.
2. In the Project window, double-click AddHotelController.xib to
launch Interface Builder.
3. Right-click the File’s Owner icon in the main nib window, as I have
done in Figure 1-7, to see the list of Outlets.
This particular dialog can also be accessed by choosing the Connections
tab in the Interface Builder Inspector.
You also see the Receiving Actions — your IBAction labeled methods.
You’ll be working on that shortly.
4. Drag from the name outlet item in the dialog onto the Name text field
in the View window, as shown in Figure 1-8.
Interface Builder now knows that the name outlet should point to that
Name text field at runtime. All is right with the world.
5. Now drag from the File’s Owner New Referencing outlet to the Name
text field as well, as I have in Figure 1-9.
When you let go of the mouse, you’ll see a pop-up menu that says del-
egate, as you can see in Figure 1-10.
6. Select delegate from the pop-up menu, as I have in Figure 1-10.
41_542934-bk07ch01.indd 75041_542934-bk07ch01.indd 750 3/23/10 11:01 PM3/23/10 11:01 PM