gpt4 book ai didi

ios - Swift - 当点击键盘上的 "done"时点击按钮

转载 作者:行者123 更新时间:2023-11-30 12:54:44 26 4
gpt4 key购买 nike

我有这样的情况:

screenshot of my app

我希望当用户从键盘上点击“完成”时,它会自动点击“登录/注册”按钮。

我读过:

我的类应该遵循协议(protocol)UITextFieldDelegate

设置密码字段的委托(delegate)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)
}

但是当我点击键盘上的“完成”按钮时,没有任何反应。

最佳答案

找到答案:

我需要调用按钮的操作并将 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
}

关于ios - Swift - 当点击键盘上的 "done"时点击按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40555953/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com