在NSTextField上按Enter键时如何做 [英] How to do something when Enter-key is pressed on NSTextField

查看:123
本文介绍了在NSTextField上按Enter键时如何做的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Swift为Mac编写应用程序.

I'm writing an app for the Mac using Swift.

我在NSTextField对象中写入一个字符串,我想将其保存在.txt文件中. 我希望这种情况在用户按下Enter键后立即发生.我的方法.writeToFile()已经准备好,一旦按下该键,我就无法弄清楚如何使其运行.

I write a string inside a NSTextField object and I would like to save it in a .txt file. I would like that to happen as soon as the user presses Enter-key. My method .writeToFile() is ready, I cannot figure out how to make it run as soon as that key is pressed.

我找不到Swift语言的正确答案.谢谢.

I could not find a proper answer for Swift language. Thank you.

推荐答案

@IBAction func textFieldAction(sender: NSTextField) {
    print(sender.stringValue)
}

这篇关于在NSTextField上按Enter键时如何做的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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