我只想知道在按下textField中的enter按钮时是否以及如何选择要做什么。
我想通过在textField中触摸Enter来从电子邮件/用户textField传递到密码textField,并通过按下“登录”按钮来触发被调用的操作。
my code trigged when the login button is pressed + my login screen
我是否需要将“ @IBAction func loginButtonWasPressed(_ sender:UIButton){}中的所有行放入函数中,并在密码textField上按enter键时调用它(idk怎么做)
谢谢您的帮助!
@IBOutlet weak var firstNameTextField: UITextField!
@IBOutlet weak var lastNameTextField: UITextField!
@IBOutlet weak var emailTextField: UITextField!
@IBOutlet weak var passwordTextField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
self.setupTextfields()
}
@IBAction func signupDidTap(_ sender: Any) {
print("Sign up")
}
func setupTextfields(){
self.firstNameTextField.addTarget(self.lastNameTextField, action: #selector(becomeFirstResponder), for: .editingDidEndOnExit)
self.lastNameTextField.addTarget(self.emailTextField, action: #selector(becomeFirstResponder), for: .editingDidEndOnExit)
self.emailTextField.addTarget(self.passwordTextField, action: #selector(becomeFirstResponder), for: .editingDidEndOnExit)
self.passwordTextField.addTarget(nil, action: #selector(signupDidTap), for: .editingDidEndOnExit)
}