简体   繁体   English

如何在首次启动时仅显示一次UIPageViewController

[英]How to show a UIPageViewController only once on first launch

I want to show a tutorial that is a UIPageView only once at the beginning of the first launch. 我想显示一个教程,它是一个UIPageView,在第一次启动的开始仅一次。

I am attempting this using this code 我正在尝试使用此代码

let launchedBefore = UserDefaults.standard.bool(forKey: "launchedBefore")
    if launchedBefore  {
        performSegue(withIdentifier: "tutorialtohome1", sender: nil)
    }
    else {
        UserDefaults.standard.set(true, forKey: "launchedBefore")
    }

For some reason it's not working with the UIPageController, it works fine with other views. 由于某种原因,它不能与UIPageController一起使用,它可以与其他视图一起正常工作。

Just to make clear, I only want this view to appear once, then never again, as it acts as a tutorial. 为了清楚起见,我只希望该视图出现一次,然后再也不会出现,因为它充当了教程。

Any suggestions? 有什么建议么?

Thanks 谢谢

You need to check the OBJECT. 您需要检查对象。 Not the bool. 不是笨蛋。 This is better way to do it. 这是更好的方法。 On first run, there are no such key "lauchedBefore". 在第一次运行时,没有这样的键“ lauchedBefore”。 You cannot check boolean value of what's not there. 您无法检查不存在的布尔值。

let launchedBefore = UserDefaults.standard.object(forKey: "launchedBefore")

    if (launchedBefore==nil)  {
        performSegue(withIdentifier: "tutorialtohome1", sender: nil)
        UserDefaults.standard.set(true, forKey: "launchedBefore")
    }
    else {
        // already launched, so do nothing.
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM