从 Carbon Code 调用 Cocoa IBAction
我正在尝试从 Carbon 代码调用 Cocoa IBAction
...
我已经使用 本教程。
热键工作正常,但我需要在按下全局键时触发 IBAction。
时,我不断收到错误消息
[self functionName]
当我使用“如何调用该函数?”
。我读过有关将 Cocoa 控制器传递给 Carbon 方法的内容。我该怎么做?或者什么是最好的方法?
I'm trying to call a Cocoa IBAction
from Carbon code...
I've set up global keys using this tutorial.
The hot keys are working fine, but I need to fire an IBAction when the global key has been pressed.
I keep getting errors when I use
[self functionName]
How do I call the function?
I've read about passing the Cocoa controller to the carbon method. How would I do this? or what is the best way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我假设您在 Carbon 事件处理程序回调中调用
[self functionName]
。这不是 Objective-C 方法,所以当然没有定义 self 。当您安装 Carbon 事件处理程序时,参数之一是“用户数据”指针。您可以在此参数中传递一个 Objective-C 对象指针,以便您的事件处理程序能够获取它,您可以说类似
[(MyController*) inUserData functionName]
的内容。当然,要使其工作,您的处理程序必须位于 Objective-C 或 Objective-C++ 源文件中。I assume you're calling
[self functionName]
in a Carbon Event handler callback. That's not an Objective-C method, so of courseself
is not defined.When you install a Carbon Event handler, one of the parameters is a "user data" pointer. You can pass an Objective-C object pointer in this parameter, so that your event handler will get it, and you can say something like
[(MyController*) inUserData functionName]
. Of course, to make this work, your handler must be in an Objective-C or Objective-C++ source file.您可以将其中之一作为用户数据传递,同时保持程序对于 C++ 翻译的安全:
you can pass one of these as your user data while keeping the program safe for c++ translations: