开发者

How to receive NSNotifications from Objective-C in C++ classes?

I have an Objective-C++ class that adds itself as an observer for an event on a Cocoa NSView. I would like to be able to send the NSNotifications to a method of a C++ class instead of an Objective-C method or block. How can I do this?

My situation is this:

  • A - Objective-C++ class
  • B - NSView

B is encapsulated by A. I want to be notified of one of B's events. However, the method handling that event MUST have a reference to the开发者_如何学编程 instance of A that contains B.


Create a dead simple wrapper class in Objective-C that points to your C++ instance and handles the notification by calling the C++ method.


You can not consume the notification with a C++ method directly, or simple C function for that matter.

You must wrap the call to the C++ method is an actual Objective-C method, or block, and then delegate forward the notification to the C++ method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜