2016-05-01 14 views
0

Ich arbeite an einem iOS-Projekt mit Swift. Ich habe einfache Login/register/verlorene Passwort-View-Controller für die Sicherheit mit Firebase. Das Problem tritt mit dem Reset Password View Controller auf. Wenn ein Benutzer darauf klickt, werden sie (modal präsentiert) an den verlorenen Passwort-View-Controller gesendet.AlertController - Konflikt mit UIViewController

Das Problem mit dem aktuellen Code ist, dass, wenn Firebase die eingegebene E-Mail findet und eine E-Mail zum Zurücksetzen des Passworts sendet, ich Alert-Controller zur Bestätigung für den Benutzer präsentiere. Das Problem ist, dass wenn ich auf dem Alert-Controller auf "OK" klicke, ich auch den Password View-Controller zurücksetzen möchte. Nicht sicher, warum es jetzt nicht funktioniert. Ich bekomme E-Mails, aber wenn ich auf den OK-Button auf dem Alert-Controller klicke, wird nur der Alert-Controller gelöscht und der self.dismissViewControllerAnimated(true, completion: nil) scheint den modal präsentierten Reset Password View Controller nicht zu verwerfen.

Ich versuchte mit self.dismissViewController(true, completion: nil) sowie self.performSegueWithIdentifier("goToLoginVC", sender: nil). Non scheint zu arbeiten und ich kann nicht verstehen warum.

Hier ist die Funktion selbst:

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

Antwort

0

Jemand beantwortet und die Lösung zur Verfügung gestellt, sondern nahm seine Antwort nach. Also, das ist, was er sagte, und es hat gut funktioniert (so geht Kredit an diese Person!):

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

Ich dachte, Sie brauche das nicht .. :) –

+0

Das war genau das, was ich brauchte! Vielen Dank! – Dani

+0

Ich freue mich, Ihnen zu helfen .. :) –

0

es auf diese Weise tun:

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

    //Add your logic here 

})) 
Verwandte Themen