How to receive notification of NSTextField textDidEndEditing from C++?
I have an 开发者_C百科Objective-C++ program that uses an NSSearchField. Specifically, the NSSearchField is wrapped in a QMacCocoaViewContainer derivative (Qt). How can I set things up so that I can receive notification of textDidEndEditing from a Qt signal? Will I need a pure Objective-C class that uses NSNotificationCenter?
If you're on iOS4, looks like you can have your notification delivered to a block instead. NSNotificationCenter sports this method:
- (id)addObserverForName:(NSString *)name object:(id)obj queue:(NSOperationQueue *)queue usingBlock:(void (^)(NSNotification *))block NS_AVAILABLE(10_6, 4_0);
Then you could do something like:
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 ] ;
}
精彩评论