使用NSNotification委派NSTextField的方法 [英] Delegate methods of NSTextField using NSNotification

查看:546
本文介绍了使用NSNotification委派NSTextField的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在窗口中有一个NSTokenField。我使用它来存储与Core Data对象相关的标签。现在我设置了,我可以添加标签到对象,但我不能删除它们。我需要一个委托方法在NSTokenField,可以让我知道什么时候用户已经将焦点移出NSTokenField。因为NSTokenField是NSTextField的子类,我想我可以使用它的委托方法。它有两个我认为可能有用:

I have an NSTokenField in a window. I am using it to store tags related to a Core Data object. Right now I have it set up such that I can add tags to the objects, but I cannot delete them. I need a delegate method on the NSTokenField that can let me know when the user has moved the focus out of the NSTokenField. Since NSTokenField is a subclass of NSTextField I figured that I could use its delegate methods. It has two that I think could be useful:

- (void)textDidChange:(NSNotification *)aNotification
- (void)textDidEndEditing:(NSNotification *)aNotification

我将控制器类设置为我的NSTokenField并把这两个方法放入我的控制器类。我把一个基本的NSLog到他们每个人,当我与NSTokenField交互时也不触发。我猜这与NSNotification有关系。如何激活这些方法?

I set my controller class as the delegate of my NSTokenField and put both of these methods into my controller class. I put a basic NSLog into each of them and neither is triggered when I interact with the NSTokenField. I am guessing it has something to do with NSNotification. How do I activate these methods?

推荐答案

NSTokenField code> controlTextDidChange:和 controlTextDidEndEditing:通知;改变以上两种方法,实现它们:

The NSTokenField invokes the controlTextDidChange: and the controlTextDidEndEditing: notifications; change the two methods above, implementing them as:

- (void)controlTextDidChange:(NSNotification*)aNotification
{
    //Code here..
}

- (void)controlTextDidEndEditing:(NSNotification *)aNotification
{
    //Code here..
}

这篇关于使用NSNotification委派NSTextField的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆