我使用 Firebase 作为后端,并编写了登录部分。当我使用测试帐户登录时,调试器打印“已登录:”。但是,当我尝试转到主视图 Controller 时,出现错误“ fatal error :在展开可选值时意外发现 nil"代码在 self.presentviewcontroller 行中断。这里做错了什么?
if email != "" && password != ""
{
FIREBASE_REF.authUser(email, password: password, withCompletionBlock: {(error, FAuthData) -> Void in
if error == nil
{
NSUserDefaults.standardUserDefaults().setValue(FAuthData.uid, forKey: "uid")
print("logged in")
self.logoutButton.hidden = false
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let secondViewController = storyboard.instantiateViewControllerWithIdentifier("ViewController") as! ViewController
self.presentViewController(secondViewController, animated: true, completion: nil)
}
else{
print("The user was not logged in")
}
})
}
else{
let alert = UIAlertController(title: "ERROR", message: "Please Enter Email and Password", preferredStyle: .Alert)
let action = UIAlertAction(title: "OK", style: .Default, handler: nil)
alert.addAction(action)
self.presentViewController(alert, animated: true, completion: nil)
}
最佳答案
检查您的主 Storyboard是否将标识符 ViewController
设置为您的 ViewController。
关于ios - 登录成功后如何呈现不同的ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36336333/