2016-05-01 27 views
0

私はSwiftを使用しているiOSプロジェクトに取り組んでいます。 Firebaseを使用してセキュリティを確保するために、単純なログイン/登録/失われたパスワード表示コントローラがあります。問題はReset Password View Controllerで発生します。ユーザがそれをクリックすると、それらは紛失したパスワードビューコントローラに送られる(モーダルに提示される)。AlertController - UIViewControllerとの競合

現在のコードの問題は、Firebaseが入力した電子メールを見つけてパスワードリセット電子メールを送信したときに、ユーザーの確認のために警告コントローラを提示することです。問題は、アラートコントローラで[OK]をクリックすると、[リセットパスワードビューコントローラ]も終了させたいということです。なぜそれが今働いていないのか分かりません。私は電子メールを取得しますが、警告コントローラの[OK]ボタンをクリックすると警告コントローラが却下され、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) 
    } 
} 

答えて

0

誰かが答えてソリューションを提供しますが、それの後に彼の答えを削除しました。だから、これは彼が言ったことであり、それがうまく働いていた(のでクレジットはその人に行く!):

@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

私は、あなたがそれを必要としないと思った... :) –

+0

私がまさに必要だったこと!ありがとうございました! – Dani

+0

あなたを助けて幸せ.. :) –

0

はそれをこのように行います:

ここで関数自体です

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

    //Add your logic here 

})) 
関連する問題