Question

i read about responder chains, and basically i read about how the events from the UI are passed up on the responder chain, how to handle them and how to pass along. I also used -becomeFirstResponder and -resignFirstResponder, but i was using these only for basic tasks, like showing keyboard on iOS and handling shake events.

What I would like to know is how can I use the "First Responder" proxy object in the MainWindow.xib that Xcode generates. I see some received actions and also i see that i can create actions on the Identity inspector tab.

So my question is: how can I use these actions, and when should I use this proxy object in IB ?!

Interface Builder Screenshot

Thanks in advance.

Was it helpful?

Solution

You would use First Responder as the target of an action whenever you want the action to be sent to the first responder, regardless of which particular object that happens to be at the time the action is sent.

In desktop Cocoa, a message targeted for the First Responder is in fact a nil-targeted action - no target is implicitly understood as the first possible responder, the First Responder.

Often, textual actions are directed to the First Responder. You want keypresses to be sent to whichever text field has focus, but the text field that has focus changes over the life of the view and of the application. You could manually retarget the action each time a text field get focus, but thanks to NSResponder, you don't have to bother - that's all taken care of for you.

OTHER TIPS

Assigning an action to the first responder object is the same as adding an action to a control with a nil target programatically. When the action is triggered, the application will go through the responder chain and send the action to the first responder that accepts it. On the mac, it is often used to automatically send menu commands to the current window or document. You should use it if you have multiple objects which you want to send messages to with the same button.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top