注册不继续到Tab View Controller

时间:2015-09-18 01:44:21

标签: ios swift

一旦用户登录我的应用程序,我需要将它们带到选项卡视图控制器,以便他们可以充分发挥应用程序的潜力。我试图在onClick函数按钮中启动TabBarController但没有成功。

PFUser.logInWithUsernameInBackground(username, password:password) {
        (user: PFUser?, error: NSError?) -> Void in
        if error == nil {
            let storyboard = UIStoryboard(name: "Main", bundle: nil)
            let vc = storyboard.instantiateViewControllerWithIdentifier("KlikurHomeTabs") as! UITabBarController
            self.presentViewController(vc, animated: true, completion: nil) // this shows it modally
        } else if error!.code == 101 {
            var invalidLogin:UIAlertView = UIAlertView(title: "Please try again", message: "The username password combo you have us does not match our records, please try again or reset your password.", delegate: self, cancelButtonTitle: "Try again")
            invalidLogin.show()
        }
    }

有人能发现我做错了吗?我没有任何线索,现在已经尝试了一段时间。谢谢:)

2 个答案:

答案 0 :(得分:0)

只需更改此行,并取出故事板代码行

       let vc = storyboard.instantiateViewControllerWithIdentifier("KlikurHomeTabs") as! UITabBarController

   let vc = self.storyboard.instantiateViewControllerWithIdentifier("KlikurHomeTabs") 
            self.presentViewController(vc!, animated: true, completion: nil) 

答案 1 :(得分:0)

这更多是关于Paulw11评论的详细阐述,但这就是我正在做的事情。我有一个" splash"视图控制器有2个故事板segues,一个到signin / signup视图控制器,一个到我的主tabview控制器。在viewDidAppear里面,我检查登录状态,然后执行两个segue中的一个。以下是代码示例。

  override func viewDidAppear(animated: Bool) {

    if needsLogin {
      performSegueWithIdentifier("SignIn/SignUP", sender: self)
    } else {
      performSegueWithIdentifier("MainTabBar", sender: self)
    }

  }