-makeFirstResponder:用法

发布于 2024-10-29 18:57:23 字数 198 浏览 3 评论 0原文

我对可可编程相当陌生,我想问是否有人可以向我解释如何 -(BOOL)makeFirstResponder:(NSResponder *)responder; 方法有效。我计划将它用于 NSEvent 但有人可以告诉我如何实现它吗?

我正在尝试使用 NSResponder 类来获取有效的 -keyDown 方法。

I am fairly new to cocoa programming and I would like to ask if anyone can explain me how to
-(BOOL)makeFirstResponder:(NSResponder *)responder; method works. I was planning on using it for NSEvent but can anyone show me how to implement it?

I am trying to use the NSResponder class to get me a working -keyDown method.

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

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

发布评论

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

评论(3

听不够的曲调 2024-11-05 18:57:23

NSResponder 是 Cocoa 中的基本类之一。任何可以响应按键或菜单命令等事件的类都应该是 NSResponder 的子类。每个响应者都跟踪它的“下一个响应者”,每个窗口都跟踪当前作为“第一响应者”的对象。当窗口中发生事件时,消息将发送到第一响应者。如果该对象处理该消息,那就太好了。如果没有,它将传递给下一个响应者。这称为“响应者链”。

通常,您不会对 Cocoa 中的响应者链造成太多混乱。第一响应者主要由用户操作决定,例如单击控件。

“将其用于 NSEvent”是没有意义的。 NSEvent 不是响应者,而是使响应者能够完成其工作的东西。

如果您更清楚地描述您想要实现的目标,我相信我们可以为您指明正确的方向。

NSResponder is one of the fundamental classes in Cocoa. Any class that can respond to events like key presses or menu commands should be a subclass of NSResponder. Each responder keeps track of it's "next responder", and each window keeps track of the object that's currently the "first responder". When an event happens in a window, a message is sent to the first responder. If that object handles the message, great. If not, it passes it along to its next responder. This is known as the "responder chain."

Normally, you don't mess much with the responder chain in Cocoa. The first responder is mostly determined by user actions, such as clicking on a control.

It doesn't make sense to 'use it for NSEvent'. NSEvent isn't a responder, but something that enables responders to do their job.

If you describe more clearly what you're trying to accomplish, I'm sure we can point you in the right direction.

寻找一个思念的角度 2024-11-05 18:57:23

您通常不会实现 -makeFirstReponder:,而是调用它来将输入焦点设置到视图。你真正想要实现的目标是什么?

You don't usually implement -makeFirstReponder:, you call it to set the input focus to a view. What is it that you really want to achieve?

半衾梦 2024-11-05 18:57:23

我正在尝试使用 NSResponder 类来获得一个有效的 keyDown 方法。

这没有道理。 “使用”一个类?

如果您想响应关键事件,通常应该在能够成为第一响应者的视图中执行此操作(请参阅 NSView 文档)。

另请参阅事件处理指南查看编程指南,以及会话 145 的视频(“关键事件处理在 Cocoa 应用程序中”)来自 WWDC 2010 会议视频(您应该能够即使您去年没有参加 WWDC,也可以通过您的开发者帐户进行访问)。

I am trying to use the NSResponder class to get me a working keyDown method.

That doesn't make sense. “Use” a class?

If you want to respond to key events, you normally should do that in a view that should be capable of becoming the first responder (see the NSView docs).

See also the Event-Handling Guide, the View Programming Guide, and the video for session 145 (“Key Event Handling in Cocoa Applications”) from the WWDC 2010 session videos (which you should be able to access through your developer account even if you didn't go to WWDC last year).

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