I can capture string when user click the button. and I also use the following method
- (BOOL)control:(NSControl *)control textShouldBeginEditing:(NSText *)fieldEditor
which declared in NSControlTextEditingDelegate Protocol. And when user begin editing, the button will be available.
My Question is: How to make the button disable when user delete all text (make the textField empty without clicking button)?
The above method seems can not do it...
If your
NSText
is aNSTextView
you may also use NSTextDelegate Protocol and NSTextViewDelegate Protocol.Among others, the
NSTextDelegate
Protocol declares this delegate method:The
NSTextDidChangeNotification
is documented here NSTextDidChangeNotificationLook at using the
NSControlTextDidChangeNotification
orcontrolTextDidChange:
delegate method (fromNSControl
) which is posted by the text field. When you receive the callback you can examine the text currently in the field to decide what to do.Many ways to do the same thing. This version lets you easily catch specific keystrokes of interest.
for instance, if you were looking for the return key, you might then implement: