Middle
Who is part of the responder chain in iOS?
sobes.tech AI
Answer from AI
The responder chain in iOS consists of objects inheriting from UIResponder. These include:
UIView(and its subclasses)UIViewController(and its subclasses)UIWindow(and its subclasses)UIApplication
The chain is constructed as follows:
- For View: the next responder is its
supervieworUIViewController, if the View is the root for the controller. - For View Controller: the next responder is its
view.superview(if any), orUIWindowif the controller is the root for the window, orUIApplication. - For Window: the next responder is
UIApplication. - For Application: the next responder is
nil(the chain ends).
The chain is used for handling events (such as touches, gestures, control actions) and commands (Actions). The event/command is passed from the first responder up the chain until one object handles it.
Example of a touch event passing:
- The
UIViewwhere the touch occurred. - Its
superview. - The next
superview. - ...
- The root
UIViewof the controller. UIViewController.UIWindow.UIApplication.