我应该使用哪种委托方法来响应 NSTextField 上的点击? [英] Which delegate method should I use to respond to clicks on an NSTextField?

查看:31
本文介绍了我应该使用哪种委托方法来响应 NSTextField 上的点击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试响应 textfield 中的 click.当点击发生时,我将打开一个面板.我最初的想法是使用 delegate 方法来响应 click 事件 - 但我发现:

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

此方法确实有效,但仅当我实际编辑文本字段中的文本时,而不是当我第一次单击它时.而且 - 如果我再次编辑文本,此方法将停止工作:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆