O'Reilly logo

Beginning iOS 5 Application Development by Wei-Meng Lee

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required