我有一个使用NSSearchField的Objective-C ++程序。具体来说,NSSearchField包含在QMacCocoaViewContainer派生(Qt)中。如何设置以便我可以从Qt信号接收textDidEndEditing的通知?我是否需要使用NSNotificationCenter的纯Objective-C类?
答案 0 :(得分:0)
如果您使用的是iOS4,看起来您可以将通知发送到某个块。 NSNotificationCenter采用这种方法:
- (id)addObserverForName:(NSString *)name object:(id)obj queue:(NSOperationQueue *)queue usingBlock:(void (^)(NSNotification *))block NS_AVAILABLE(10_6, 4_0);
然后你可以这样做:
MyClass.m:
static void (^receiveNote)(NSNotification *) = ^(NSNotification * note)
{
UITextField * field = [ note object ] ;
// forward notification to C++ here
} ;
...
@implementation MyClass
...
-(void)setUpNotifications
{
[ [ NSNotificationCenter defaultCenter ] addObserverForName:UITextFieldTextDidChangeNotification
object:self.textField
queue:[ NSOperationQueue mainQueue ]
usingBlock:receiveNote ] ;
}