1

I have a NSTextField and want to send an action whenever the user changes the value. I checked "Continuous" in the Interface Builder (which works i.e. fine with NSSlider), but the NSTextField only sends his action if I unfocus it. How can I continuously send an action from a NSTextField (using Swift)?

ixany
  • 5,433
  • 9
  • 41
  • 65

1 Answers1

5

Set the delegate of the text field to the class which is supposed to receive the action and implement

func controlTextDidChange(_ obj: NSNotification)

This method is invoked when text in a control such as a text field or form changes. The control posts a NSControlTextDidChangeNotification notification, and if the control’s delegate implements this method, it is automatically registered to receive the notification. Use the key @"NSFieldEditor" to obtain the field editor from the userInfo dictionary of the notification object.

vadian
  • 274,689
  • 30
  • 353
  • 361