我正在研究应该隐藏在登录视图后面的应用程序。嵌入在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)
应该驳回提出模态登录视图控制器,因为我看到在控制台打印语句。
我的错误在哪里?