简体   繁体   中英

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.

在Objective-C中创建一个死的简单包装类,它指向C ++实例并通过调用C ++方法处理通知。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM