OUTLETS AND ACTIONS

Outlets and actions are fundamental mechanisms in iOS programming through which your code can connect to the views in your user interface (UI). When you use outlets, your code can programmatically reference the views on your UI, with actions serving as event handlers that handle the different events fired by the various views.

Although you can write code to connect actions and outlets, Interface Builder simplifies the process by enabling you to use the drag-and-drop technique.

Creating Outlets and Actions

In Xcode 4, Interface Builder further simplifies the creation of outlets and actions. To create an action in Interface Builder, first click the Assistant Editor button to open another code editor pane next to the XIB file (see Figure B-31). In the new editor, select the .h file of the View Controller representing the XIB file.

Control-click the Round Rect Button and drag it onto the .h file as shown in Figure B-32.

image

FIGURE B-31

image

FIGURE B-32

You will be prompted to create either an outlet or an action. In this case, create an action as shown in Figure B-33 and then click the Connect button.

image

FIGURE B-33

Xcode will automatically create the declaration for the action ...

Get Beginning iOS 5 Application Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.