Friday, May 6, 2011

Delegate methods of NSTextField using NSNotification

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

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?

From stackoverflow
  • 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..
    }
    
  • hi can you help me?

    • (void)textDidChange:(NSNotification *)aNotification

    {

    the code?

    }

0 comments:

Post a Comment