ios - AlertController - 与 UIViewController 冲突

标签 ios swift uiviewcontroller uialertcontroller

我正在使用 Swift 开发一个 iOS 项目。我有简单的登录/注册/丢失密码 View Controller ,以使用 Firebase 实现安全性。问题出在重置密码 View Controller 上。如果用户单击它,它们将被发送(以模式方式呈现)到丢失密码 View Controller 。

当前代码的问题是,当 Firebase 找到输入的电子邮件并发送密码重置电子邮件时,我会显示警报 Controller 以供用户确认。问题是,当我在警报 Controller 上单击“确定”时,我希望重置密码 View Controller 也被关闭。不知道为什么它现在不起作用。我确实收到了电子邮件,但是当我单击警报 Controller 上的“确定”按钮时,它只会关闭警报 Controller ,并且 self.dismissViewControllerAnimated(true,completion: nil) 似乎不会关闭模态提出了重置密码 View Controller 。

我尝试使用self.dismissViewController(true,completion:nil)以及self.performSegueWithIdentifier(“goToLoginVC”,sender:nil)。 Non 似乎有效,但我不明白为什么。

这是函数本身:

    @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)
    }
}

最佳答案

这样做:

alertController.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle. Default, handler: { action in

   //Add your logic here

}))

关于ios - AlertController - 与 UIViewController 冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36967569/

相关文章:

javascript - iOS Safari,视频和比例呈现缓慢的问题

ios - IB Designables : Failed to render and update auto layout status (Google Maps)

函数声明返回任何东西,也无效?

ios - 如何向 ViewController 添加填充/边距

ios - 应用程序不要求照片库使用权限

iOS NSMutableArray 值在离开 AlertView 后变为 nil

ios - NSPredicate 返回对象而不是属性字符串值

swift - 等待完成再执行下一步

ios - 检索我们处于生命周期 Controller 的哪个状态

ios - StackView插入偏移问题