xcode NSTextField 没有诸如“编辑已更改”之类的事件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2351266/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 19:09:24  来源:igfitidea点击:

No events such as 'Editing did Change' for a NSTextField?

objective-cxcodeeventsmacosnstextfield

提问by adrianderbaum

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 …)

当我为 iPhone 开发时,我有多个触摸事件,这对于按钮来说可能是正确的。(例如,编辑确实发生了变化,编辑确实结束了……)

Now that I develop for Mac OSX I want my application to recognize multiple events in a NSTextField.

现在我为 Mac OSX 开发,我希望我的应用程序能够识别 NSTextField 中的多个事件。

How to do that? Is there an alternative for the events?

怎么做?活动有替代方案吗?

Thanks!

谢谢!

EDIT: May delegates be the key?

编辑:代表可能是关键吗?

回答by Rob Keniger

You need to set an object as the delegate of your NSTextField. As NSTextFieldis a subclass of NSControl, it will call the -controlTextDidChange:method on your object if you implement it.

您需要将一个对象设置为您的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