xcode Swift 检测按下的返回键而不使用 textFieldDidEndEditing

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40300142/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 09:30:34  来源:igfitidea点击:

Swift detect return key pressed without using textFieldDidEndEditing

iosswiftxcodeuitextfield

提问by Frederik

Is there a way to detect that the return key was pressed on the keyboard without using textFieldDidEndEditing. textFieldDidEndEditingis also triggered if you for example perform a segue which dismisses the keyboard.

有没有办法在不使用textFieldDidEndEditing. textFieldDidEndEditing例如,如果您执行关闭键盘的 segue,也会触发。

回答by Annie Gupta

The below delegate is called when you press the return key.

当您按下返回键时,将调用以下委托。

func textFieldShouldReturn(textField: UITextField) -> Bool {
    print("return pressed")
    textField.resignFirstResponder()
    return false
}