Im trying to implement a delegate for a NSTextField object so I can detect the user input in real time and give some feedback about no allowed input in that particular field.
Especially, I want to simulate the onChange()
method from JavaScript, detecting the user input in real time and show him a warning if it is writing a non supported value.
i.e. The app have a text field it only accept numeric values from 0 to 255 (like RGB values) and I want to know when the user is writing not numeric values or out of range values to instantly show him a warning message or change the text field background color, just a visual hint to let him know the input it's wrong.
Like you see on the pictures above, I want to show a warning sign every time the user inputs a forbidden value in the text field.
I have been reading a lot of the Apple's documentation but I don't understand which delegate to implement (NSTextFieldDelegate
, NSTextDelegate
, or NSTextViewDelegate
), also, I have no idea how to implement it in my AppDelegate.m
file and which method use and how to get the notification of user editing.
Right now, I already set the Delegate in my init
method with something like this [self.textField setDelegate:self];
but I don't understand how to use it or which method implements.