IOS Response Chain Original http://blog.csdn.net/yadong000/article/details/8837241
The first thing to be clear is that in iOS, there are responder chains that respond to events, all response classes are subclasses of Uiresponder, and the responder chain is a hierarchy of different objects in which each object is given an opportunity to respond to an event message in turn.
The process of the response chain:
When an event occurs, the response chain is first sent to the first responder (often the view that the event occurred, where the user touches the screen). The event will be passed along the responder chain, knowing that it is accepted and processed. In general, the first response is a view object or its subclass, and when it is touched, the event is handed over to it, and if he does not process it, the time is passed to the View Controller object Uiviewcontroller (if present) and then to its top object (Superview). And so you know the top-level view. The next step is to move along the top view to the window (the UIWindow object) to the program's (UIApplication object), and if the whole process does not respond to the event, the event is discarded, and in general the event is passed as long as there is an object handling event in the response chain.
A typical response roadmap is as follows:
First Responser--the Window-->the applicationn--App Delegate
The normal responder chain process is often interrupted by a delegate, and one object may delegate the response work to another object (typically the view controller Viewcontroller).
Frequently asked questions about the response chain:
1. How to invoke a method in the controller of the parent class:
[[Self Superview].nextresponder Method]; or [[[Self Superview] nextresponder] method];
Both of these methods are possible, but it is best to make a judgment when using:
ID next = [self nextresponder]; class]]) //Can't jump out here ... Some people say here can not jump out, in fact, because it does not have the current view into the Viewcontroller, nature will not jump out, will die cycle, use needs attention. { next = [next Nextresponder]; } class]]) { Controller = (Viewcontroller *) next;}
2. When a sub-view needs to receive a click event, its parent view also needs to receive the Click event, what to do with it:
Under normal circumstances, when a subclass receives a click event, the event is not actively delivered to the next responder, so the parent class no longer receives the Click event. If a subclass does not handle a click event, the event is passed down until uiapplication.
But we can make the child class handle the response event and still pass the response to the next responder. But we write code to do it.
To do this: the code for the Child view is as follows:-(void) Touchesbegan: (Nsset *) touches withevent: (Uievent *)Event {//Here you can do the sub-view of what you want to do, when done, the event continues to upload, you can let its parents, even the parent Viewcontroller get to this event [[Selfnextresponder]touchesbegan: Toucheswithevent:event];} -(void) touchesended: (Nsset *) touches withevent: (uievent *)event { [selfnextresponder]touchesended: Toucheswithevent:event];} -(void) touchescancelled: (Nsset *) touches withevent: (uievent *)event { [[Selfnextresponder] Touchescancelled:toucheswithevent:event];} -(void) touchesmoved: (Nsset *) touches withevent: (uievent *)event { [[Selfnextresponder] touchesmoved: Toucheswithevent:event];}
Add a summary:
Extract part of the description:
" when users interact with the iphone's touchscreen, the hardware detects physical contact and notifies the operating system. The operating system then creates the corresponding event and passes it to the event queue for the currently running application. The event is then passed to the priority responder object by the event loop. A priority responder object is an object that interacts with the user when the event is triggered, such as a button object or view object. If we write code that allows a priority responder to handle this type of event, it will handle this type of event. After an event has been processed, the responder has two options: 1, discards it, and 2, passes it to the next responder in the response chain. The address of the next responder is stored in the variable Nextresponder that the current responder object contains. If a priority responder cannot handle an event, the event is passed on to the next responder until the event reaches the responder who can handle it or arrives at the end of the response chain, which is the UIApplication type object. An object of type uiapplication is either processed or discarded after receiving an event. "
For example, there is a View object, which has a button object on it. When the user touches the button object, the button object receives an event as a priority responder. If the button object cannot handle the event, the event is passed to the View object. If the view object cannot handle this event, the event is passed to the view controller object. And so on
It should be noted that when we are using the response chain, an event does not automatically pass from one responder to the next responder. If you want to pass an event from one responder to the next, we must write code to do so. "
IOS response Chain