我试图避免整体开始/登录屏幕,并在用户登录时直接进入应用程序的第一页。当我运行下面的代码时,没有任何反应。我断点了,它说当前用户为nil,但是当 View 加载时,当前用户不是nil。
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
self.storyboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
var currentUser = PFUser.currentUser()
print("user \(currentUser)")
if currentUser != nil {
if(currentUser?.username?.rangeOfString("@music.co") != nil){
self.storyboard?.instantiateViewControllerWithIdentifier("venuehomescreen")
}else{
self.window?.rootViewController = self.storyboard?.instantiateViewControllerWithIdentifier("userhomescreen")
}
}
}
最佳答案
我通常在我的应用程序中正常处理登录 View Controller ,而不是在该登录 View Controller 的 viewDidAppear 中,我添加类似于以下的逻辑:
if PFUser.currentUser() != nil{
//perform segue
//or present view controller modally
}
将登录 View Controller 置于层次结构中非常重要,例如注销,这样您就可以放松到登录 View Controller 。
此外,有必要在 viewDidAppear 中执行 segue,因为只有在要转换的 View Controller 已添加到层次结构之后,您才必须执行 View Controller 转换。
关于ios - 如何使用 PFUser 更改初始 View Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36230315/