我试图在用户选择第一个 AlertViewController 中的操作后呈现新警报。请在下面找到我的代码。
@IBAction func forgotPassword(sender : AnyObject){
//1. Create the alert controller.
let alert = UIAlertController(title: "Forgot Password?", message: "We'll email a link to reset it.", preferredStyle: .Alert)
//2. Add the text field. You can configure it however you need.
alert.addTextFieldWithConfigurationHandler({ (textField) -> Void in
textField.placeholder = "Email Address"
})
//3. Grab the value from the text field, and print it when the user clicks OK.
alert.addAction(UIAlertAction(title: "Send", style: .Default, handler: { (action) -> Void in
let textField = alert.textFields![0] as UITextField
let email = textField.text!
FIRAuth.auth()?.sendPasswordResetWithEmail(email) { error in
if error != nil {
// An error happened.
} else {
print("error is nil")
if self.presentedViewController != nil {
self.presentedViewController?.dismissViewControllerAnimated(true, completion: {
print("inside completion")
let alertController = UIAlertController(title: "Email Sent!", message: "Please check you email and follow the password reset instructions", preferredStyle: .Alert)
let action = UIAlertAction(title: "Done", style: .Default, handler: nil)
alertController.addAction(action)
self.presentViewController(alertController, animated: true, completion: nil)
})
}
}
}
}))
// 4. Present the alert.
self.presentViewController(alert, animated: true, completion: nil)
}
无论我在完成块中编写什么代码,它都不会被执行,因此第二个警报不会显示。请帮我解决这个问题。
UIAlertView 似乎会在执行操作后自行关闭。
//3. Grab the value from the text field, and print it when the user clicks OK.
alert.addAction(UIAlertAction(title: "Send", style: .Default, handler: { (action) -> Void in
let textField = alert.textFields![0] as UITextField
guard let email = textField.text else {
return
}
FIRAuth.auth()?.sendPasswordResetWithEmail(email) { error in
if let error = error {
print(error.localizedDescription)
return
}
let alertController = UIAlertController(title: "Email Sent!", message: "Please check you email and follow the password reset instructions", preferredStyle: .Alert)
let action = UIAlertAction(title: "Done", style: .Default, handler: nil)
alertController.addAction(action)
self.presentViewController(alertController, animated: true, completion: nil)
}
}))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)