【问题标题】:AlertController - conflict with UIViewControllerAlertController - 与 UIViewController 冲突
【发布时间】: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


    【解决方案1】:

    这样做:

    alertController.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle. Default, handler: { action in
    
       //Add your logic here
    
    }))
    

    【讨论】:

      【解决方案2】:

      有人回答并提供了解决方案,但在此之后删除了他的答案。所以,这就是他所说的,而且效果很好(所以归功于那个人!):

          @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)
      
                      alertController.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: { action in
      
                          self.dismissViewControllerAnimated(true, completion: nil)
      
                      }))
                      self.presentViewController(alertController, animated: 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)
          }
      }
      

      【讨论】:

      • 我以为你不需要那个.. :)
      • 这正是我所需要的!谢谢!
      • 很高兴为您提供帮助.. :)
      猜你喜欢
      • 2013-04-29
      • 1970-01-01
      • 2017-12-09
      • 2013-10-21
      • 2020-08-19
      • 2010-12-10
      • 2018-04-02
      • 2021-10-23
      • 2020-12-03
      相关资源
      最近更新 更多