Game Development Reference
In-Depth Information
Creating New IBOutlets from Interface Builder
An
IBOutlet
is a connection between an item defined in a XIB file and a variable declared in a class.
To specify a field as an
IBOutlet
, you simply put the keyword before the declaration of a field in
a classes header file. Another way to create an
IBOutlet
is to create it through Interface Builder.
Figure
2-17
shows how to create an IBOutlet in Interface Builder.
Figure 2-17.
Creating an IBOutlet in Interface Builder
In Figure
2-17
, we see the steps to create an IBOutlet in Interface Builder. The first thing to notice is
that the view on the right is split between Interface Builder and a code window. To enable this split
view, press command+option+return. To create the IBOutlet, start by right-clicking on the object
you want to create an IBOutlet for (A)—in this case, the Portrait Holder view. From the dialog that
pops up, drag your mouse from the little circle to the right of New Referencing Outlet (B) to the place
in the code where you want the
IBOutlet
created (C). As can be seen in Figure
2-17
, a number of
IBOutlet
references are already created. Note that the header file where these
IBOutlet
references
are created is
ViewController.h
. We use this file
ViewController_iPhone
, and
ViewController_iPad
will inherit them. Lets take a look at the complete version of ViewControler.h in Listing 2-5.