2

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...

4

3 回答 3

2

如果你NSText是一个NSTextView你也可以使用NSTextDelegate ProtocolNSTextViewDelegate Protocol

其中,NSTextDelegate协议声明了这个委托方法:

textDidChange:

通知委托文本对象已更改其字符或格式属性。

- (void)textDidChange:(NSNotification *)aNotification

讨论

aNotification 的名称是 NSTextDidChangeNotification。

NSTextDidChangeNotification此处记录NSTextDidChangeNotification

于 2013-10-15T15:08:45.280 回答
1

查看使用文本字段发布的NSControlTextDidChangeNotificationcontrolTextDidChange:委托方法(from )。NSControl当您收到回调时,您可以检查当前字段中的文本以决定做什么。

于 2013-10-15T14:57:16.230 回答
0

许多方法可以做同样的事情。此版本可让您轻松捕捉感兴趣的特定击键。

- (BOOL)textView:(NSTextView *)aTextView shouldChangeTextInRange:(NSRange)affectedCharRange replacementString:(NSString *)replacementString{
     NSLog(@"last character entered: %@",replacementString);
}

例如,如果您正在寻找返回键,那么您可以实现:

if ([replacementString characterAtIndex:0] == NSNewlineCharacter)
    NSLog(@"return pressed");
于 2014-02-09T01:05:15.560 回答