Search code examples
cocoamacos-carbonibaction

Calling Cocoa IBAction from Carbon Code


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?


Solution

  • I assume you're calling [self functionName] in a Carbon Event handler callback. That's not an Objective-C method, so of course self 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.