我正在研究應該隱藏在登錄視圖後面的應用程序。嵌入在Tab View Controller中的受保護視圖?
所以一般來說,我有一個選項卡導航控制器應該保存幾乎整個應用程序,我的邏輯是應用程序加載時,初始視圖控制器是選項卡導航控制器,它顯示其第一個視圖如果用戶是登錄。如果它沒有登錄,他們應該看到登錄/註冊頁面。登錄和註冊頁面都與Parse一起工作,它們都可以正常運行。它們在選項卡視圖控制器的第一個視圖的頂部以模態方式呈現(使用segues)。
問題是,當我登錄(我確認它的工作原理!)登錄視圖控制器不排除爲了看到選項卡視圖控制器,我認爲我可能已經搞砸在塞格東西了。如果用戶沒有登錄,則顯示登錄視圖的segue是從受保護的視圖(不是它的導航控制器,儘管我也測試過,不起作用)登錄視圖控制器。
此外,在受保護的頁面的代碼是這樣的:
override func viewDidAppear(animated: Bool) {
self.performSegueWithIdentifier("segueToLoginView", sender: self)
}
這裏是我的故事板是什麼樣子:
所以,登錄SEGUE有模式地提出和這裏的我的登錄按鈕的代碼。
@IBAction func loginButtonTapped(sender: AnyObject) {
let username = usernameTextField.text
let password = passwordTextField.text
// Sends to Parse to see if user exists
PFUser.logInWithUsernameInBackground(username!, password: password!) {
(user: PFUser?, error: NSError?) -> Void in
if user != nil {
// LOGIN Successful
NSUserDefaults.standardUserDefaults().setBool(true, forKey: "isUserLoggedIn")
NSUserDefaults.standardUserDefaults().synchronize()
self.dismissViewControllerAnimated(true, completion: nil)
print("User logged in")
} else {
// Display Failed Login Alert message with confirmation
let failedLoginAttepmt = UIAlertController(
title: "Ups!",
message: "Something went wrong, try again...",
preferredStyle: UIAlertControllerStyle.Alert
)
let confirmAction = UIAlertAction(
title: "OK!",
style: UIAlertActionStyle.Default)
{ action in
self.dismissViewControllerAnimated(true, completion: nil)
}
failedLoginAttepmt.addAction(confirmAction)
self.presentViewController(failedLoginAttepmt, animated: true, completion: nil)
print("Could not find the user")
}
,這行代碼self.dismissViewControllerAnimated(true, completion: nil)
應該駁回提出模態登錄視圖控制器,因爲我看到在控制檯打印語句。
我的錯誤在哪裏?