问题
When I developed for the iPhone I had multiple events on touch that could be true for a button. (e.g. Editing did Change, Editing did End …)
Now that I develop for Mac OSX I want my application to recognize multiple events in a NSTextField.
How to do that? Is there an alternative for the events?
Thanks!
EDIT: May delegates be the key?
回答1:
You need to set an object as the delegate of your NSTextField
. As NSTextField
is a subclass of NSControl
, it will call the -controlTextDidChange:
method on your object if you implement it.
@interface MyObject : NSObject
{
IBOutlet NSTextField* textField;
}
@end
@implementation MyObject
- (void)awakeFromNib
{
[textField setDelegate:self];
}
- (void)controlTextDidChange:(NSNotification *)notification
{
if([notification object] == textField)
{
NSLog(@"The contents of the text field changed");
}
}
@end
来源:https://stackoverflow.com/questions/2351266/no-events-such-as-editing-did-change-for-a-nstextfield