2016-04-10 4 views
0

ユーザーのログインが成功したら、別のビューに切り替えたいと思っています。ラッピング条件が満たされていないにもかかわらず、セグを実行するのはなぜですか?

@IBAction func loginAction(sender: UIButton) { 
    let email = self.email.text 
    let password = self.password.text 

    if (email != "" && password != "") { //check that password and email are entered 
     BASE_REF.authUser(email, password: password, withCompletionBlock: { (error, authData) -> Void in 
      if (error != nil) { //check if login was successful 
       print(error) 
      } else { 
       NSUserDefaults.standardUserDefaults().setValue(authData.uid, forKey: "uid") 

       print ("Logged in :)") 

       self.performSegueWithIdentifier("loginSuccessful", sender: nil) 
       self.logoutButton.hidden = false 
      } 
     }) 
    } else { //otherwise, return error and show alert 
     let alert = UIAlertController(title: "Error", message: "Enter Email and Password", preferredStyle: .Alert) 

     let action = UIAlertAction(title: "OK", style: .Default, handler: nil) 

     alert.addAction(action) 

     self.presentViewController(alert, animated: true, completion: nil) 
    } 
} 

segueはelseブロック内にあります。 ifブロックは、ユーザをログインさせる際にエラーがあったかどうかをチェックし、エラーがあればそれを表示します。間違ったIDが渡されたときにエラーが表示されますが、アプリはまだとにかく続行します。

なぜこのようなことが起こり、どうすれば防止できますか?

ありがとうございます。

+1

あなたはストーリーボードおよびNotボタンでのViewControllerからセグエを作成していることを確認します。 –

+2

ストーリーボード接続を投稿してください。 Rahul氏によると、SegueはViewControllerとViewControllerの間にあるはずです。 –

答えて

0

固定:問題は、2つのViewControllerの間ではなく、ボタンとViewControllerの間にセグがあることでした。

2つのViewController間のセグを再作成することで問題は解決しました。アルン・グプタとラーフルKatariyaへ

  • クレジット
関連する問題