I am trying to use NSTextField to input an integer user. The text field is bound to the NSNumber property, and in the setter method I clear the input value (make sure it is int) and set the property if necessary. I am sending willChangeValueForKey: and didChangeValueForKey :, but the user interface is not updated to new values while this text field is still active.
So, for example, I can type “12abc” into the text box, which the setter method clears to “12”, but the text box still shows “12abc”.
I have the value "Continuous Update" set in the interface builder.
(I also noticed that the setter method gets an NSString, not an NSNumber. Is this normal?)
What is the correct way to connect NSTextField to NSNumber? What does the setter method for a property look like? How to prevent non-numeric values from appearing in a text box?
source
share