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

試著忘記壹切 提交于 2019-12-22 04:47:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!