How Outlets and Actions Work

At the start of this chapter, I explain that you need to be able to connect the objects you added to your user interface in Interface Builder to code that enables you to access these objects (such as to an Image view to change its image) or receive a message that the user has tapped a button.

In the chapter, I show you how to create outlets and actions to do that, but I haven’t really explained how all that is connected at runtime.

As I explain in Chapter 4, storyboards are a collection of (resource) nib files that you use to store the user interface of your application.

A nib file is an Interface Builder document. When you use Interface Builder in Chapter 4 to create your user interface, you create an object graph that is saved (archived) as part of the resource file. When you load the file, the object graph is then used to re-create the relationships between the objects in the file, and your program objects as well.

As I explain in Chapter 6, every storyboard file has an initial view controller. At runtime, it’s loaded along with its view and all of the other Interface Builder objects you added in Chapter 5 — and you get an exact replica of the objects that were in your Interface Builder document. The nib-loading code instantiates the objects, configures them, and reestablishes any inter-object connections including the outlets and actions that you created in Interface Builder. Not bad for a bunch of 0’s and 1’s, right?

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.