问题描述
我读到了响应者链,基本上我读到了关于如何在响应者链上传递来自UI的事件,如何处理它们以及如何传递。我还使用了-becomeFirstResponder和-resignFirstResponder,但我只是将它们用于基本任务,比如在iOS上显示键盘和处理震动事件。
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.
我想知道什么我如何在Xcode生成的MainWindow.xib中使用First Responder代理对象。我看到一些收到的操作,我也看到我可以在Identity检查器选项卡上创建操作。
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.
所以我的问题是:我如何使用这些操作,何时应该在IB中使用此代理对象?
So my question is: how can I use these actions, and when should I use this proxy object in IB ?!
提前致谢。
推荐答案
您可以使用First Responder作为行动的目标您希望将操作发送给第一个响应者,而不管发送操作时恰好是哪个特定对象。
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.
在桌面Cocoa中,一条消息第一响应者的目标实际上是 nil
- 目标行动 - 没有目标被隐含地理解为第一个可能的响应者,第一响应者。
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.
通常,文本操作会定向到第一响应者。您希望将按键发送到具有焦点的文本字段,但具有焦点的文本字段会在视图和应用程序的生命周期中发生更改。您可以在每次文本字段获得焦点时手动重新定位操作,但是由于 NSResponder
,您不必费心 - 这一切都将由您完成。
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.
这篇关于“第一响应者”怎么样?在xib文件中使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!