Jesus
Jesus

Reputation: 8576

how to know which NSTextField has been modified its value

I have several NSTextFields declared on my NSWindowController, all of them has as delegate the File's Owner, and respond fine to this method:

-(void)controlTextDidEndEditing:(NSNotification *)obj{

}

but I also want to know the control's value for this I used next code

-(void)controlTextDidEndEditing:(NSNotification *)obj{
    if ((NSTextField *)obj == self.nombreCuentaActivoTextField) {
        NSLog(@"you just edited nombreCuentaActivoTextField");
    }
}

but it doesn't work, how to do that

Upvotes: 1

Views: 137

Answers (1)

Ken Thomases
Ken Thomases

Reputation: 90531

obj is an NSNotification. You can't just cast it to an NSTextField and assume you've achieved anything useful.

The control which posted that notification and thus triggered that delegate method is the "object" of the notification. You can use [obj object] to obtain that. So, you might implement the method like so (I've renamed obj to notification for clarity):

-(void)controlTextDidEndEditing:(NSNotification *)notification{
    if ([notification object] == self.nombreCuentaActivoTextField) {
        NSLog(@"you just edited nombreCuentaActivoTextField");
    }
}

Upvotes: 2

Related Questions