我遇到这种情况:
我希望当用户从键盘上点击“完成”时,它会自动点击“登录/注册”按钮。
我读过:
我的班级应该遵循协议UITextFieldDelegate
设置密码字段passwordTextField.delegate = self
然后做这样的事情:
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
// releasing the focus on the textField and hiding the keyboard
passwordTextField.resignFirstResponder()
self.tapOnSignIn()
return true
}
然后我创建了tapOnSignIn函数
func tapOnSignIn() {
self.signinupButton.sendActions(for: .touchDown)
}
但是当我点击键盘上的“完成”按钮时,没有任何反应。
答案 0 :(得分:0)
找到答案:
我需要为我的按钮调用操作并将self
作为参数传递:
self.signinupTapped(self)
现在我的职能是:
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
// releasing the focus on the textField and hiding the keyboard
passwordTextField.resignFirstResponder()
self.signinupTapped(self)
return true
}