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
Swift detect return key pressed without using textFieldDidEndEditing
提问by Frederik
Is there a way to detect that the return key was pressed on the keyboard without using textFieldDidEndEditing
. textFieldDidEndEditing
is 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
}