【发布时间】:2016-05-01 14:07:59
【问题描述】:
我正在使用 Swift 开发一个 iOS 项目。我有简单的登录/注册/丢失密码视图控制器,以确保使用 Firebase 的安全性。问题在于重置密码视图控制器。如果用户单击它,它们将被发送(以模态方式呈现)到丢失密码视图控制器。
当前代码的问题在于,当 Firebase 找到输入的电子邮件并发送密码重置电子邮件时,我会提供警报控制器以供用户确认。问题是当我在警报控制器上单击“确定”时,我希望重置密码视图控制器也被解除。不知道为什么它现在不起作用。我确实收到了电子邮件,但是当我单击警报控制器上的确定按钮时,它只会关闭警报控制器,self.dismissViewControllerAnimated(true, completion: nil) 似乎并没有关闭模态呈现的重置密码视图控制器。
我试过self.dismissViewController(true, completion: nil) 和self.performSegueWithIdentifier("goToLoginVC", sender: nil)。非似乎工作,我不知道为什么。
这是函数本身:
@IBAction func resetPasswordPressed(sender: AnyObject) {
let email = emailTextField.text
if email != "" {
DataService.ds.REF_BASE.resetPasswordForUser(email, withCompletionBlock: { error in
if error != nil {
// Error - Unidentified Email
showAlert(title: "Unidentified Email Address", msg: "Please, re-enter the email you have registered with.", actionButton: "OK", viewController: self)
} else {
// Success - Sent recovery email
let alertController = UIAlertController(title: "Email Sent", message: "An email has been sent. Please, check your email now.", preferredStyle: UIAlertControllerStyle.Alert)
let okAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
alertController.addAction(okAction)
self.presentViewController(alertController, animated: true, completion: nil)
self.dismissViewControllerAnimated(true, completion: nil)
}
})
} else {
showAlert(title: "Error!", msg: "Email is required in order to reset your password. Please, enter your email. ", actionButton: "OK", viewController: self)
}
}
【问题讨论】:
标签: ios swift uiviewcontroller uialertcontroller