Objective-C,自动擦除NSTextField字符串

问题描述:

我一直在试图找出如何自动擦除NSTextField中的字符串,点击它内部。

I've been trying to figure out how to auto erase a string within an NSTextField upon clicking within in it.

例如,当前的行为在OSX上是这样的:

For example the current behavior is like this on OSX:


当用户单击单元格或默认焦点是单元格时,该单词有时会突出显示或光标放在文本的中间。然后,用户需要使用退格删除文本(我想通过自动删除文本消除)。

When a user clicks in the cell or the default focus is the cell either the word is sometimes highlighted or the cursor is placed in the middle of the text. The user then needs to use backspace to delete the text (which I'd like to eliminate by automatically removing the text).

这是一个内置的函数,我不知何故丢失了?

Is this a function that is built-in that I'm somehow missing? If not how would I go about it?

有很多可怕的想法盒外,这是一个

There are plenty of terrible ideas "outside the box", and this is one of them.

无论如何,创建 NSTextField 的子类。覆盖 becomeFirstResponder 。如果 [super becomeFirstResponder] 返回 YES ,请设置 self.stringValue = @ code>。

Anyway, make a subclass of NSTextField. Override becomeFirstResponder. If [super becomeFirstResponder] returns YES, set self.stringValue = @"".