我应该使用哪个委托方法来响应NSTextField的点击? [英] Which delegate method should I use to respond to clicks on an NSTextField?
问题描述
我想回应文本字段
中的点击
。当点击发生时,我打开一个面板
。我最初的想法是使用委托
方法来响应点击
事件 - 但我发现:
I am trying to respond to a click
within a textfield
. When the click occurs, I am going to open a panel
. My initial thought was to use a delegate
method to respond to the click
event - but I found that:
此方法无效:
(void)textDidBeginEditing:(NSNotification *)aNotification
这种方法可以工作, em>编辑 文本字段中的文本,而不是我第一次点击它。 - 如果我第二次编辑文本,此方法停止工作:
This method does work, but only when I actually edit the text within the text field, not when I first click it. And - if I edit the text a second time, this method stops working:
(void)controlTextDidBeginEditing:(NSNotification *)aNotification
我可以尽可能多地使用一个代码示例,理想。我知道 nstextfield
继承自 NSControl
,它有一个 mouseDown
事件。是否有类似的方法用 textfield
来响应事件?
I could use as much detail as possible - or a code example, ideally. I know that an nstextfield
inherits from NSControl
, which has a mouseDown
event. Is there a similar way to respond to the event with a textfield
, also?
推荐答案
由于 NSTextField
继承了 NSControl
类,它还继承了 - void)mouseDown:(NSEvent *)theEvent
方法。
Since NSTextField
inherits from the NSControl
class, it also inherits the -(void)mouseDown:(NSEvent*) theEvent
method.
这篇关于我应该使用哪个委托方法来响应NSTextField的点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!