Adding Outlets

To recap from the previous section, outlets are the way your code can access — either by sending messages or setting properties — the Interface Builder objects in your storyboard. In previous versions of Xcode, you had to declare an outlet in the header file of a class and make a connection between the outlet and another object using Interface Builder. Now, however, you can do all this graphically in Interface Builder, and the required code is generated for you. Read on to find out more about how this works.

Opening the Assistant editor

To create an outlet, you need to connect the interface object in Interface Builder with your code. Although you have a couple of ways to make this connection, the easiest and most clear- cut way is to use the Assistant editor to automatically display the code file that’s most relevant to the interface element you’re working with. To make the Assistant editor automatically display a likely code file, follow these steps:

1. Select the MainStoryboard_iPad.storyboard file in the Project navigator.

2. Close the Utility area if it’s open (and you need the space) by deselecting it in the View selector in the Xcode toolbar.

3. In Interface Builder, select the View Controller – TestDrive in the View Controller – TestDrive Scene (see, it is handy to actually label things) in the Document Outline; and then click the Assistant Editor button in the Editor selector in the toolbar (see Figure 9-3).

The Assistant editor pane opens and displays ...

Get iPad Application Development For Dummies, 3rd Edition 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.