2016-08-02 69 views
0
override init() { 
    super.init() 

    parseLoginHelper = ParseLoginHelper {[unowned self] user, error in 
     // Initialize the ParseLoginHelper with a callback 
     if let error = error { 
      // 1 
      ErrorHandling.defaultErrorHandler(error) 
     } else if let _ = user { 
      // if login was successful, display the TabBarController 
      // 2 
      let storyboard = UIStoryboard(name: "Main", bundle: nil) 
      let tabBarController = storyboard.instantiateViewControllerWithIdentifier("TabBarController") 
      // 3 
      self.window?.rootViewController!.presentViewController(tabBarController, animated:true, completion:nil) 
     } 
    } 
} 

因此,我明白这里的代码应该能够在登录时替换我的登录屏幕,但是它不会。相反,它会加载并保留在登录屏幕上进行解析。但是,如果我退出该应用程序,它会加载正确的屏幕。有没有人有任何想法如何更有效地关闭登录屏幕登录?使用解析时在iOS中关闭登录屏幕

let user = PFUser.currentUser() 

let startViewController: UIViewController; 

if (user != nil) { 
    // 3 
    // if we have a user, set the TabBarController to be the initial view controller 
    let storyboard = UIStoryboard(name: "Main", bundle: nil) 
    startViewController = storyboard.instantiateViewControllerWithIdentifier("TabBarController") as! UITabBarController 
} else { 
    // 4 
    // Otherwise set the LoginViewController to be the first 
    let loginViewController = PFLogInViewController() 
    loginViewController.fields = [.UsernameAndPassword, .LogInButton, .SignUpButton, .PasswordForgotten] 
    loginViewController.delegate = parseLoginHelper 
    //loginViewController.signUpController?.delegate = parseLoginHCelper 

    startViewController = loginViewController 
} 

// 5 
self.window = UIWindow(frame: UIScreen.mainScreen().bounds) 
self.window?.rootViewController = startViewController; 
self.window?.makeKeyAndVisible() 

return false 
} 
+0

所以要添加一些子视图,你在里面打开该视图 - 控制?这个init在哪里? –

+0

@Lu_不知道我是否理解你的问题? –

+0

所以我会用其他方式问,我们不知道你的代码应该替换什么,因为我们不知道这个init在哪里,你能告诉我更多的东西吗? –

回答

0

我相信你不应该叫

self.window?.rootViewController!.presentViewController(tabBarController, animated:true, completion:nil) 

,而是如果你已经在一些控制器为什么只去的TabBar这样的:

presentViewController(tabBarController, animated:true, completion:nil) 
+0

与上述相同的问题..它说现在是一个未解决的成员 –

0

,则不应使用:

self.window?.rootViewController!.presentViewController(tabBarController, animated:true, completion:nil) 

试着改变那个l由国家统计局:

let storyboard = UIStoryboard(name: "Main", bundle: nil) 
    let vc = storyboard.instantiateViewControllerWithIdentifier("tabBarController") as! tabBarController 
    self.presentViewController(vc, animated: true, completion: nil) 

和故事板,设置tabBarController的故事板ID下的身份检查器:tabBarController

+0

试图..给我presentViewController没有会员礼物 –