我有一个 C++ 类,最近从 *.cpp 重命名为 *.mm 以支持 Objective-C。所以我可以添加以下 Objective-C 代码。
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(notificationHandler:)
name:@"notify"
object:nil];
- 如何/可以用 C++ 编写 notificationHandler 方法?
- 设置 addObserver:self 属性会起作用吗?
或者你也可以只使用块并执行以下操作:
[
[NSNotificationCenter defaultCenter] addObserverForName: @"notify"
object: nil
queue: nil
usingBlock: ^ (NSNotification * note) {
// do stuff here, like calling a C++ method
}
];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)