So I have an NSStepper object tied to a NSTextField and I have implemented the controlTextDidEndEditing delegate. The problem is that when the text field is modified by the stepper the delegate does not fire. If the text field is modified directly, it works fine. What can I do to be notified of NSStepper edits?
Bonus – I don’t understand the difference between textDidChange_ and controlTextDidChange. I cold never get the former to work. Any help is appreciated. Thanks. --Andrew
If you want a stepper and text field to stay coordinated, the easiest way is to bind the value of both to the same property.
The former is what triggers the latter. So the only time you would normally call it would be if you had changed the value in a non-key-value-observable way, and you wanted to force the notification.
In that case probably the easiest thing to do is to connect the stepper to an action handler.
As you’ve seen, making changes via bindings doesn’t trigger delegate methods. If it did, the delegate methods would in turn trigger the bindings mechanism, and you’d have a vicious cycle.
Another way to do this, if you want to be notified when the value changes by any means (and you don’t need to know which control changed it) is to use a setter method for the property that both the stepper and text field are bound to. One disadvantage (possibly) of the controlTextDidChange method is that it’s called each time you type a character rather than just at the end of editing (though you can use controlTextDidEndEditing instead).
Thanks guys. For some reason I was making things more difficult than I needed. Another case of “over thinking” I guess. I appreciate the help. --Andrew