仅当文本字段不为空或不相同时,我想显示新的ViewController
。我总是单击按钮将用户导航到下一个视图,即使不满足条件也要这样做。
@IBAction func nextButtonPressed(_ sender: Any) {
self.performSegue(withIdentifier: "goToLastRegisterView", sender: self)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if usernameTextField.text == "" || passwordTextField.text == "" || confirmedPasswordTextField.text == "" {
errorLabel.isHidden = false
errorLabel.text = "All fields are required"
}
else{
if passwordTextField.text == confirmedPasswordTextField.text{
if segue.identifier == "goToLastRegisterView"{
let secondRegisterVC = segue.destination as! RegisterSecondViewController
secondRegisterVC.userName = usernameTextField.text!
secondRegisterVC.password = passwordTextField.text!
}
}
else{
errorLabel.isHidden = false
errorLabel.text = "Different passwords"
}
}
}
答案 0 :(得分:0)
如果您进行了self.performSegue(withIdentifier:
操作,现在要检查override func prepare(for
内的文本副本为时已晚,则必须通过按钮操作进行操作
@IBAction func nextButtonPressed(_ sender: Any) {
if usernameTextField.text == "" || passwordTextField.text == "" || confirmedPasswordTextField.text == "" {
errorLabel.isHidden = false
errorLabel.text = "All fields are required"
return
}
self.performSegue(withIdentifier: "goToLastRegisterView", sender: self)
}