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
}
所以要添加一些子視圖,你在裏面打開該視圖 - 控制?這個init在哪裏? –
@Lu_不知道我是否理解你的問題? –
所以我會用其他方式問,我們不知道你的代碼應該替換什麼,因爲我們不知道這個init在哪裏,你能告訴我更多的東西嗎? –