gpt4 book ai didi

swift - 当我关闭 Onboarding 并第二次运行应用程序时出现 AppDelegate 问题

转载 作者:行者123 更新时间:2023-11-30 10:29:49 26 4
gpt4 key购买 nike

我使用 UIPageViewController 进行登录工作,但是当我第二次运行该应用程序时,Xib 不工作

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

//////OnBoarding
let lunchbefor = UserDefaults.standard.bool(forKey: "haslunched")
self.window = UIWindow(frame: UIScreen.main.bounds)
let lunchstoryboard = UIStoryboard(name: "onboarding", bundle: nil)
let mainstoryboard = UIStoryboard(name: "Main", bundle: nil)

var vc: UIViewController
if lunchbefor{
window?.rootViewController = MainVC()
vc = mainstoryboard.instantiateInitialViewController()!

}else{
vc = lunchstoryboard.instantiateViewController(withIdentifier: "start")
}
UserDefaults.standard.set(true, forKey: "haslunched")
if lunchbefor == false{

self.window?.rootViewController = vc
self.window?.makeKeyAndVisible()
}else{
window?.makeKeyAndVisible()
window?.rootViewController = MainVC()

}

return true
}

错误:

Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value"

在这一行:

vc = mainstoryboard.instantiateInitialViewController()!

最佳答案

我找到了答案我这样做了:

  var vc: UIViewController

if lunchbefor{
window?.rootViewController = MainVC()
// vc = mainstoryboard.instantiateInitialViewController()!
vc = MainVC()

}else{
vc = lunchstoryboard.instantiateViewController(withIdentifier: "start")
}

关于swift - 当我关闭 Onboarding 并第二次运行应用程序时出现 AppDelegate 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59389688/

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