8

Is it possible to get an event when you click on a token in a NSTokenField?

Chris Hanson
  • 54,380
  • 8
  • 73
  • 102
Tom Nys
  • 579
  • 6
  • 13

1 Answers1

4

Seeing as those tokens (NSTokenFieldCells) inherit from the NSCell class, in theory, yes, you can have them send an event by giving them an action and a target (-setAction: and -setTarget: respectively, and if you want to give the tokens menus when pressed, use -setMenu:).

Itai Ferber
  • 28,308
  • 5
  • 77
  • 83
  • How/where should I set the action which will be fired when clicking on a token field cell? – brutella Jan 09 '11 at 14:18
  • In your UI controller (whichever class you use to control actions associated with the user interface), you should declare a method that will get called when these tokens get pressed. By default, there's no way to access `NSTokenFieldCell`s from the `NSTokenField` to set the action and target, though, so you might have to do some subclassing to get it to work correctly. – Itai Ferber Jan 09 '11 at 14:50
  • I have created a MyNSTokenField to return MyNSTokenFieldCell (through + (Class)cellClass, whereby I set MyNSTokenFieldCell's Target and Action though no event was sent. Any idea what else I could do to get an event when clicked? – Tom Nys Jan 10 '11 at 15:01
  • I'm wondering the same thing. Did you managed to get it solved? – Tony Jan 01 '12 at 00:50