Responder Chain in iPhone

The File Owner is an instantiated, run-time object that owns the contents of your nib and it's outlets/actions when the nib is loaded.

A responder is an object that can respond to events and handle them. If the first responder cannot handle an event or action message, it forwards it to the "next responder" in a linked series called the "responder chain".

The responder chain is the order in which various objects are given the chance to handle an event. In a simple case, suppose we have a button in a NSView in a NSWindow in a NSApp. When the button is clicked, the button will have the first opportunity to handle the event, then its controller, then the NSView, then its controller, then the NSWindow, then its delegate, then the NSApp and its delegate. In this way, an object is first given a chance to handle the event, then its controller/delegate, then the container of the object and so on. 

Responder-chain -in-iPhone.jpg

Suppose you have a hierarchy of views such that there exists a superview A that has subview B and B has a subview C. Now you touch on the inner most view C. The system will send a touch event to subview C for handling this event. If C View does not want to handle this event, this event will be passed to its superview B (the next responder). If B also does not want to handle this touch event it will pass it on to superview A. All the views that can respond to touch events are called the responder chain. A view can also pass its events to uiviewcontroller. If the view controller also does not want to respond to the touch event then it is passed to the application object that discards the event.


Similar Articles