0
我想在用戶登錄成功時繼續使用不同的視圖。即使包裝條件不符合,爲什麼segue仍然執行?
@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時打印的,但是,該應用仍然無法播放。
爲什麼會發生這種情況,我該如何預防它!
謝謝?
確保你在故事板和沒有按鈕創建的SEGUE從視圖控制器。 –
發佈您的故事板連接。正如Rahul所說,Segue應該在Viewcontrollers之間,而不是從按鈕到ViewController。 –