2 Replies Latest reply: Mar 7, 2011 8:30 PM by Steve Herman1
moofmama Level 1 Level 1 (20 points)
Hey,
I am having a problem researching the use of the textfield delegates. I have a window with several discrete textfields. In the class that I have specified as the delegate I get the


-(void)controlTextDidEndEditing:(NSNotification *)obj


event when a field is exited. I need to know which of the fields triggered the event so that I know how to respond.

Searching the documentation led me in circles for quite a while. I had to try a few of the delegate methods to find out which ones that my fields send. After that had a few more circles with finding out that the notification obj contains the fieldeditor in the userInfo dictionary under the key @"NSFIeldEditor"

The docs contain a lot of info about subclassing the fieldEditor and about working with textfieldcells but I haven't found the whats and hows of the fieldEditor yet.

Most of the code examples I have found are too simple in that they only have one field and can just operate on that. Can anyone point me at info that tells me what I can do with the fieldEditor?

MM

MacBook Pro, Mac OS X (10.6.5), many
  • 1. Re: NSTextField and delegate notification
    moofmama Level 1 Level 1 (20 points)
    I am not sure if this is the best way to do it but I am using the tag property of the control to identify the object that send the notification.



    -(BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor{
    //save the tag from the control
    int theTag = [control tag];
    }


    Anybody else find something more elegant?

    MM
  • 2. Re: NSTextField and delegate notification
    Steve Herman1 Level 4 Level 4 (2,545 points)
    If you're interested in using controlTextDidEndEditing like you orginally planned then the object method of NSNotification should return the object that posted the notification. For example:

    -(void)controlTextDidEndEditing:(NSNotification *)obj
    {
    NSTextField * whichNSTextField = (NSTextField *)[obj object];
    }


    Steve