我有一个应用程序和一个引导屏幕,如果用户第一次打开应用程序,我想显示引导屏幕,但我做错了。我应该将代码放在AppDelegate还是放在我的第一个屏幕的ViewDidLoad中。
这是我使用的代码:
super.viewDidLoad()
if UserDefaults.standard.bool(forKey: "isFirstLaunch") {
UserDefaults.standard.set(true, forKey: "isFirstLaunch")
UserDefaults.standard.synchronize()
}
let isFirstLaunch = UserDefaults.standard.value(forKey: "isFirstLaunch") as? Bool
if isFirstLaunch! {
let mainStoryboard = UIStoryboard(name: "ViewController", bundle: Bundle.main)
let vc : ViewController = mainStoryboard.instantiateViewController(withIdentifier: "ViewController") as! ViewController
self.present(vc, animated: true, completion: nil)
}
并且有一个错误的图片:
有什么想法如何解决?