当我为iPhone开发时,我在触摸上有多个事件,对于一个按钮来说可能是真的。(例如,编辑did Change,编辑did End…)
现在我已经为Mac进行了开发,我希望我的应用程序能够识别NSTextField中的多个事件。
如何做到这一点?这些事件有没有其他选择?
谢谢!
编辑:代表可能是关键吗?
发布于 2010-03-01 09:37:54
您需要将一个对象设置为NSTextField
的代理。因为NSTextField
是NSControl
的子类,所以如果您实现它,它将在您的对象上调用-controlTextDidChange:
方法。
@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
复制相似问题