OUTLETS AND ACTIONS

As you begin to program iOS applications, you need to first understand the concept of outlets and actions. In iOS programming, you use actions and outlets to connect your code to the various views in your UI. Think of actions as event handlers in the traditional object-oriented programming world, and outlets as object references. If you are familiar with traditional programming languages such as Java or C#, this is a concept that requires some time to get used to — not because it is difficult, but because it is a different way of doing things. At the end of this section, you will have a solid understanding of what outlets and actions are in iOS and how to create them, and be on your way to creating great iOS applications.

TRY IT OUT: Creating Outlets and Actions

image

  1. Using Xcode, create a Single View Application (iPhone)project and name it OutletsAndActions. You will also use the project name as the Class Prefix and ensure that you have the Use Automatic Reference Counting option unchecked.
  2. Select the OutletsAndActionsViewController.xib file in order to edit it using Interface Builder. Populate the View window with three views: Label, Text Field, and Round Rect Button. Set the Label with the text “Please enter your name” by double-clicking on it. Set the Round Rect Button with the “OK” string (see Figure 3-1).

    Figure 3-1

  3. In Xcode, modify the OutletsAndActionsViewController.h ...

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.