无法实现UIAlertController。无法获得提醒以显示

时间:2019-01-15 17:24:22

标签: ios swift firebase alert uialertcontroller

我已设置警报,以示警告:当某些用户尝试通过Firebase请求新密码时发生任何错误,但它不起作用。

print("problems with email field")正在打印,因此我相信在编写警报部件时我做错了事。

@IBAction func recuperarSenha(_ sender: Any) {

    Auth.auth().sendPasswordReset(withEmail: self.loginTextView.text!) { error in
        if error != nil {
            print("problems with email field")

            let alert = UIAlertController(title: "Couldn't send recover message", message: "Check if e-mail field is properly filled.", preferredStyle: .alert)
            alert.addAction(UIAlertAction(title: "OK!", style: .default, handler: nil))

        }
    }
}

1 个答案:

答案 0 :(得分:1)

创建警报后,需要显示警报。添加操作后添加以下代码:

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

您的代码的编辑版本:

@IBAction func recuperarSenha(_ sender: Any) {

  Auth.auth().sendPasswordReset(withEmail: self.loginTextView.text!) { error in
    if error != nil {
        print("problems with email field")

        let alert = UIAlertController(title: "Couldn't send recover message", message: "Check if e-mail field is properly filled.", preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: "OK!", style: .default, handler: nil))
        self.present(alert, animated: true, completion: nil)


    }
  }
}