Working with the Target-Action Design Pattern
The other requirement of a user interface that I mention at the beginning of this chapter is being able to deal with situations where you want to connect a button to your code so that when a user taps the button, something happens. This requirement involves using the Target-Action pattern, which is one of the key design patterns in iOS programming.
You use the Target-Action pattern to let your app know that it should do something when prompted. A user might tap a button or enter some text, for example, and the app must respond in some way. The control — a button, say — sends a message (the Action message) that you specify to the target (the receiving object, which is usually a view controller object) that you have selected to handle that particular action.
Using the Target-Action pattern: It’s about controls
When a user acts on the control by, say, tapping a button, the iPad generates an event. The event triggering a particular action message can be anything, just as the object sending the message can be any object. For example, a gesture-recognizer object might send an action message to another object when it recognizes its gesture. However, the Target-Action pattern is usually found with controls such as buttons and sliders.
The event as such probably doesn’t tell you much, but Target-Action provides a way to send an application-specific instruction to the appropriate object.
If you wanted to develop an app that could start a car ...