问题
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