在多个文本字段上隐藏键盘

时间:2018-06-05 16:46:42

标签: ios swift uitextfield iboutlet

我尝试了几个代码,我仍然很糟糕,所以我感谢任何对Swift noob的帮助。

每次按下回车键时,我想在多个文本字段上隐藏键盘。

到目前为止,我所拥有的代码没有取得任何进展,所以任何帮助都会受到高度赞赏。

谢谢!

var newSections = Object.assign(this.state.sections)

2 个答案:

答案 0 :(得分:0)

UITextFieldDelegate

的正确方法
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
   textField.resignFirstResponder()
   return true 
}

将其替换为您命名为priceTextFieldShouldReturn

的名称

答案 1 :(得分:0)

您需要为每个文本字段设置委托。

priceTextField.delegate = self 
payoutTextField.delegate = self 
leasingPeriodTextField. delegate = self

并从UITextFieldDelegateProtocol

实施此方法
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
   textField.resignFirstResponder()
   return true 
}
相关问题