Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/94.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 为什么它总是说密码不是';不匹配?_Ios_Swift - Fatal编程技术网

Ios 为什么它总是说密码不是';不匹配?

Ios 为什么它总是说密码不是';不匹配?,ios,swift,Ios,Swift,它不断向我显示“密码不匹配”警报,我看不出问题出在哪里。 如果我删除与密码匹配的代码,它就会崩溃。 我确信IB插座和IBAction已正确连接 @IBAction func signupButton(_ sender: UIButton) { let userEmail = email let userPassword = password let userRepeatPassword = repeatPassword //

它不断向我显示“密码不匹配”警报,我看不出问题出在哪里。 如果我删除与密码匹配的代码,它就会崩溃。 我确信IB插座和IBAction已正确连接

@IBAction func signupButton(_ sender: UIButton) {
        let userEmail = email
        let userPassword = password
        let userRepeatPassword = repeatPassword



        // Check empty fields
        if (email.hasText == false) || (password.hasText == false) || (repeatPassword.hasText == false) {
            alertMessage(userMessage: "All fields are required!")
            return
        }

        // Check if passwords match
        if repeatPassword != password {
            alertMessage(userMessage: "Passwords do not match!")
            return
        }


        // Store data
        UserDefaults.standard.set(userEmail, forKey: "userEmail")
        UserDefaults.standard.set(userPassword, forKey: "userPassword")
        UserDefaults.standard.synchronize()

        // Display alert message with confirmation
            var alert = UIAlertController(title: "Alert", message: "Signed up!", preferredStyle: UIAlertController.Style.alert)

            let okAction = UIAlertAction(title: "Ok", style: UIAlertAction.Style.default) { action in
                self.dismiss(animated: true, completion: nil)
            }

            alert.addAction(okAction)

            self.present(alert, animated: true, completion: nil)
    }

    func alertMessage (userMessage: String) {
        var alert = UIAlertController(title: "Alert", message: userMessage, preferredStyle: UIAlertController.Style.alert)

        let okAction = UIAlertAction(title: "Ok", style: UIAlertAction.Style.default, handler: nil)

        alert.addAction(okAction)

        self.present(alert, animated: true, completion: nil)
    }
}

我怀疑这些说法是错误的:

    let userEmail = email
    let userPassword = password
    let userRepeatPassword = repeatPassword
考虑到您的其他代码,我怀疑
电子邮件
,其他代码是UITextFields,而不是字符串。我猜你的意思是:

    let userEmail = email.text ?? ""
    let userPassword = password.text ?? ""
    let userRepeatPassword = repeatPassword.text ?? ""

我怀疑这些说法是错误的:

    let userEmail = email
    let userPassword = password
    let userRepeatPassword = repeatPassword
考虑到您的其他代码,我怀疑
电子邮件
,其他代码是UITextFields,而不是字符串。我猜你的意思是:

    let userEmail = email.text ?? ""
    let userPassword = password.text ?? ""
    let userRepeatPassword = repeatPassword.text ?? ""