Information Technology Reference
In-Depth Information
Linking objects to code
Creating actions and outlets is a relatively simple process. Unlike previous versions of Xcode, Xcode 4 adds the
correct code automatically. It creates suitable properties, synthesizes them, and adds method code stubs. Of
course, you must fill out the method stubs with your own event handler code, but the essential elements that
support your code are added for you.
Adding an action
The button should do something useful when it's tapped. In iOS, this means adding code to create an action
method that handles button events.
The IBViewController class manages the UI. So the code is added to this class.
In theory, all controls in iOS can send any of the event messages that are predefined in iOS. Whenever you cre-
ate an action for a control, the list of events shown in the Connections Inspector in Figure 7.24 appears.
In practice, not all controls implement all events. For example, a button isn't editable, so it makes no sense for it
to send an Editing Did Begin message.
The Touch Down message does make sense; it's sent when the user taps a button. To add code that can handle a
Touch Down message, drag a line from the circle next to Touch Down in the Connections Inspector, and release
it in the area under the curly brackets in the header code.
As shown in the figure, you see a floating location line that marks the insertion point and a tool tip labeled In-
sert Action.
Search WWH ::




Custom Search