【问题标题】:No events such as 'Editing did Change' for a NSTextField?NSTextField 没有诸如“Editing did Change”之类的事件?
【发布时间】:2011-01-22 00:24:24
【问题描述】:

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

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

如何做到这一点?是否有替代活动?

谢谢!

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

【问题讨论】:

    标签: objective-c xcode events macos nstextfield


    【解决方案1】:

    您需要将一个对象设置为您的NSTextField 的代理。由于NSTextFieldNSControl 的子类,如果你实现它,它会在你的对象上调用-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
    

    【讨论】:

      猜你喜欢
      • 2011-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-25
      • 1970-01-01
      • 2013-03-22
      相关资源
      最近更新 更多