Information Technology Reference
In-Depth Information
NOTE
The view property is pre-linked for you in the view-based application template. Most of the other templates in-
clude pre-linked outlets. It's useful to review them; they can give you insight into how the nib hierarchy is organ-
ized and how the templates have been engineered.
Using First Responder
At first sight, the First Responder placeholder can seem even more abstract than File's Owner. But the principle
is simple.
All iOS and OS X applications include a responder chain— an implied hierarchy of objects that dispatches user
events. Here's what to expect:
Windows, views, and certain other objects are subclasses of an abstract event management class
( UIResponder in iOS and NSResponder in OS X).
This class includes a prewritten selection of methods that can handle standard user events such as copy,
paste, undo, and so on.
You can add your own custom events to this list.
Unlike a standard action, these messages are passed from object to object until a matching event handler
method is found. A common test sequence is view⇒view controller⇒window⇒application, but this may
vary, because it depends on the design of the application.
The First Responder icon is the connection point for this chain. It lists all the valid handler methods, in
all objects that are part of the responder chain. It's the central event handler for an application, and provides
a convenient single access point for responder methods that may be scattered across multiple objects.
Events without a handler are ignored.
In practice, you link objects that generate messages to the responder chain in the usual way. For example, in the
sample IB application, shown in Figure 8.2, you can drag a link between one of the button events, such as a
Touch Up Inside, to a responder handler, such as Copy.
A critical difference is that this doesn't generate code for you. IB doesn't know which object you want to add
the handler code to, so it doesn't try to guess. Instead, you must add the code by hand to whichever responder
object suits your needs.
Typically, this means copying a method signature from the UIResponder or NSResponder class—for ex-
ample, for the copy: method—and creating your own full implementation.
CAUTION
The methods you need to implement aren't mentioned in the UIResponder Class Reference. They're defined in the
UIResponderStandardEditActions Protocol Reference, which is part of the UIKit Framework Reference. You won't
find them unless you know this document exists. It's worth repeating again that you should review all the referen-
ces used in a framework; otherwise, you may miss critical features. To add custom methods to the responder
Search WWH ::




Custom Search