“第一响应者”如何才能做到这一点?在 xib 文件中使用?

发布于 2024-10-11 11:37:03 字数 425 浏览 6 评论 0原文

我读到了有关响应者链的内容,基本上我读到了有关来自 UI 的事件如何在响应者链上传递、如何处理它们以及如何传递的内容。我还使用了 -becomeFirstResponder 和 -resignFirstResponder,但我仅将它们用于基本任务,例如在 iOS 上显示键盘和处理摇动事件。

我想知道的是如何在 Xcode 生成的 MainWindow.xib 中使用“First Responder”代理对象。我看到一些收到的操作,而且我还看到我可以在“身份检查器”选项卡上创建操作。

所以我的问题是:我如何使用这些操作,以及何时应该在 IB 中使用此代理对象?!

Interface Builder Screenshot

提前致谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

最美的太阳 2024-10-18 11:37:03

将操作分配给第一响应者对象与以编程方式向具有 nil 目标的控件添加操作相同。当操作被触发时,应用程序将遍历响应者链并将操作发送给第一个接受它的响应者。在Mac上,它经常用于自动发送菜单命令到当前窗口或文档。如果您想使用同一按钮向多个对象发送消息,则应该使用它。

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.

寂寞笑我太脆弱 2024-10-18 11:37:03

每当您希望将操作发送到第一响应者时,您都可以使用第一响应者作为操作的目标,无论发送操作时恰好是哪个特定对象。

在桌面版 Cocoa 中,针对第一响应者的消息实际上是一个以 nil 为目标的操作 - 没有目标被隐式地理解为第一个可能的响应者,即第一响应者。

通常,文本操作会发送给第一响应者。您希望将按键发送到具有焦点的文本字段,但是具有焦点的文本字段在视图和应用程序的生命周期中会发生变化。每次文本字段获得焦点时,您都​​可以手动重新定位操作,但有了 NSResponder,您不必费心 - 这一切都为您处理好了。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文