gpt4 book ai didi

ios - fatal error : unexpectedly found nil while unwrapping an Optional value on performing segue

转载 作者:行者123 更新时间:2023-11-30 13:16:59 25 4
gpt4 key购买 nike

我正在使用 facebook SDK 登录,一切都已正确设置。当我第一次授权我的应用程序时,segue 将执行到我的下一个 View Controller 。但是当我注销并尝试再次登录时,segue 出现错误

fatal error :在解包可选值时意外发现 nil

这是我的 appDelegate 文件中的代码

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool{

let result = FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)

if result {

let token = FBSDKAccessToken.currentAccessToken()
let fieldsMapping = [
"id" : "facebookId",
"name" : "name",
"email": "email"
]

backendless.userService.loginWithFacebookSDK(
token,
fieldsMapping: fieldsMapping,
response: { (user: BackendlessUser!) -> Void in

print("user: \(user)")
self.backendless.userService.setStayLoggedIn(true)
loadUser()
// Access the storyboard and fetch an instance of the view controller
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let viewController: MainScreenViewController = storyboard.instantiateViewControllerWithIdentifier("loginViewController") as! MainScreenViewController

let rootViewController = self.window!.rootViewController! as UIViewController
print(rootViewController)
rootViewController.presentViewController(viewController, animated: true, completion: nil)


},
error: { (fault: Fault!) -> Void in
print("Server reported an error: \(fault)")
})
}

return result
}

错误发生在rootViewController.presentViewController(viewController,animated:true,completion:nil)

我尝试在 viewDidAppear() 中的 viewController 中执行 segue,并且还尝试了 PerformSegueWithIdentifier() 但错误仍然存​​在。如果我终止我的应用程序并重试,segue 工作正常。请建议我问题出在哪里。提前致谢。

最佳答案

我认为没有 rootViewController 所以你需要像下面这样设置

 func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {

var rootView: MyRootViewController = MyRootViewController()

if let window = self.window{
window.rootViewController = rootView
}
return true
}

然后在后记中使用它。

关于ios - fatal error : unexpectedly found nil while unwrapping an Optional value on performing segue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38115389/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com