Graphics Programs Reference
In-Depth Information
The Responder Chain
UIResponder
can receive touch events.
UIView
is one example of a
UIResponder
subclass, but there are many others, including
UIViewController
,
UIApplication
,
and
UIWindow
. You are probably thinking, “But you can't touch a
UIViewControl-
ler
. It's not an on-screen object.” You are right - you can't send a touch event
directly
to a
UIViewController
, but view controllers can receive events through the
responder
chain
. (By the way, you get two bonus points for keeping the view controller and its view
separate in your brain.)
Every
UIResponder
has a pointer called
nextResponder
, and together these objects
make up the responder chain (
Figure 19.3
). A touch event starts at the view that was
touched. The
nextResponder
of a view is typically its
UIViewController
(if it has
one) or its superview (if it doesn't). The
nextResponder
of a view controller is typic-
ally its view's superview. The top-most superview is the window. The window's
nex-
tResponder
is the singleton instance of
UIApplication
. If the application doesn't
handle the event, then it is discarded. (Note that the window and application don't do any-
thing with an event unless you subclass them.)
Figure 19.3 Responder chain