Kevin
Kevin

Reputation: 1479

Cocoa - controlTextDidEndEditing issue

I have the following delegate method which is listening for when text changes in an editable field:

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

Say, I have two NSTextFields declared, how can I find out which is the NSTextField that generated the notification? I want to perform some code when one text field's text did finish editing and other code when the other text field's code finishes editing.

In other words, how can I get the name of the text field that gave the notification?

Thank you!

Upvotes: 0

Views: 606

Answers (2)

Greg Steiner
Greg Steiner

Reputation: 767

You could use tags and get the tag field of the object, but first you have to force downcast the object from Any to NSTextField so you can access the tag property (an object of "any" doesn't have a "tag" property) like so:

let object = aNotification.object as! NSTextField

then you can check the tag:

if object.tag == 99 { do something }

That's how I addressed the issue in some of the code I'm working on now.

Upvotes: 0

Ken Thomases
Ken Thomases

Reputation: 90521

[aNotification object] is the NSControl (or NSControl subclass) object which posted the notification.

Upvotes: 1

Related Questions