输入NSTextField触发动作 [英] NSTextField enter to trigger action

查看:70
本文介绍了输入NSTextField触发动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一个简单的示例,该示例说明在文本字段中按Enter键时如何触发动作(或按钮)。

I've been looking all over for a simple example of how to have an action (or button) be triggered when the enter key is hit in the text field.

我应该继承文本字段吗?我需要设置一个代表来调用我需要的操作吗?有没有办法在我的主窗口控制器类中捕获该事件?

Should I subclass the text field? Would I need to set a delegate to call the action I need? Is there a way to catch the event in my main window controller class?

如果您甚至可以将我指向正确的方向,那就太好了。谢谢。

If you could even just point me to the right direction that would be great. Thanks.

推荐答案

要在点击后执行操作,只需在窗口控制器中编写IBAction并连接到文本字段即可。如果您更希望在关注文本字段并保留文本字段时应调用方法,则需要设置委托(请参见此处)。

To get action after you hit enter just write an IBAction in your window controller and connect to your text field. If you want more like your method should be called when you focus on text field and leave the text field you need to set delegate(See here).

这篇关于输入NSTextField触发动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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