4

I am relatively new to IPhone coding, although I have reached the point of working on a genuine (hopefully) saleable app.

But one thing that is still mysterious is the responder chain. All the books give passing reference to it, but I have not found one yet that describes how to modify that chain. Another curiosity is that, when the First Responder icon is clicked in the IB, a little hookup box comes up with all sorts of choices to hook up to something, but I've never found any explanation of that.

Does anyone know of an in-depth explanation of this responder process?

RedBlueThing
  • 42,006
  • 17
  • 96
  • 122
John R Doner
  • 2,242
  • 8
  • 30
  • 36

2 Answers2

3

Here's Jeff Lamarches explanation of the responder chain. While not at all exhaustive, it should get you thinking on the right track.

ennuikiller
  • 46,381
  • 14
  • 112
  • 137
  • I'm struggling with the same question here, but it seems that the link to Jeff Lamarches' explanation is down. Any chance any of you guys know if it was moved somewhere else? – BadgerBadger Mar 28 '17 at 04:54
2

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. There are other cases that are much more complicated.

An object handles an event by implementing -(void)respondToFictionalEvent:(UIEvent *)event. If this happens, then the event is "consumed" (prevented from being automatically passed further up the chain).

Regexident
  • 29,441
  • 10
  • 93
  • 100
Casebash
  • 114,675
  • 90
  • 247
  • 350
  • Actually, I'm not sure if the button has a chance to respond or if the first responder is the super view. – Casebash Jan 14 '10 at 23:11
  • 2
    The First Responder, whatever it is, button, text field, view, other, gets the chance to respond first. Then its next responder, which is usually, but doesn't have to be, its superview. An object's controller doesn't generally get involved in the responder chain. You would have to explicitly set the controller as the next responder. Only windows' delegates and the app delegate are automatically included. – jscs Apr 01 '11 at 04:14