How to do something when Enter-key is pressed on NSTextField

自古美人都是妖i 提交于 2019-12-01 10:02:10

问题


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

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.

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


回答1:


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



来源:https://stackoverflow.com/questions/27049783/how-to-do-something-when-enter-key-is-pressed-on-nstextfield

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!