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が渡されたときにエラーが表示されますが、アプリはまだとにかく続行します。
なぜこのようなことが起こり、どうすれば防止できますか?
ありがとうございます。
あなたはストーリーボードおよびNotボタンでのViewControllerからセグエを作成していることを確認します。 –
ストーリーボード接続を投稿してください。 Rahul氏によると、SegueはViewControllerとViewControllerの間にあるはずです。 –