【发布时间】:2020-05-24 19:05:02
【问题描述】:
我试图在应用程序用户以错误的方式登录或注册时向他们显示错误,例如密码需要 6 个字符,所以如果他/她输入 4 或 5,它应该会给他带来错误,但它只会在 Xcode 中打印并且在应用程序中始终为零(我是新来的,网站告诉我图片太大而无法上传,所以我会写下来)。有人可以帮我弄清楚这里的代码有什么问题吗?谢谢!!
// This is the code for the first viewcontroller where I try to pass the error to the ErrorViewController
if let email = emailTextfield.text, let password = passwordTextfield.text{
Auth.auth().signIn(withEmail: email, password: password) { [weak self] authResult, error in
if let e = error {
print(e)
self!.performSegue(withIdentifier: "GoToError", sender: self)
func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "GoToError" {
let GoTo = segue.destination as! ErrorViewController
GoTo.errorText = "\(e.localizedDescription)"}
}
}else{
self!.performSegue(withIdentifier:K.loginSegue, sender: self)
}
}
}
// This is the code of the ErrorViewController where It should catch the error and pass it to the ErrorText label and get printed to the app screen
errorText: String?
@IBOutlet weak var ViewMessage: UIView!
@IBOutlet weak var ErrorText: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
ViewMessage.layer.cornerRadius = ViewMessage.frame.size.height / 4
if errorText != nil {
ErrorText.text = errorText
}else{
// The string below is what gets printed because the error is always nil
ErrorText.text = "make sure your password is at least 6 characters"
【问题讨论】:
标签: ios swift xcode error-handling segue