如何在第一次运行应用程序(例如教程)期间使 uiviewcontroller 仅可见一次? [英] how can I make the uiviewcontroller visible only once during first run of the app (e.g. tutorial)?

查看:19
本文介绍了如何在第一次运行应用程序(例如教程)期间使 uiviewcontroller 仅可见一次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个 iOS swift 应用程序,我想在用户第一次运行该应用程序时显示教程屏幕.稍后,随着应用程序的每次运行,教程应该被隐藏,另一个视图控制器应该作为起点可见.到目前为止,我的故事板看起来像这样:

I'm creating an iOS swift app and I want to show tutorial screen when user runs the app for the very first time. Later on, with each run of the app the tutorial should be hidden and another view controller should be visible as a starting point. So far my storyboard looks like this:

它包含两个屏幕的教程(第一个和最后一个)和标签栏(这是我的应用程序的主窗口).

It contains two screens of tutorial (1st and last) and tab bar (which is a main window of my app).

至于现在,在故事板中,我选择标签栏作为初始视图控制器:

As for now, in storyboard I chose the tab bar to be an initial view controller:

使用这种方法,永远不会看到教程屏幕.如何在首次启动应用时只显示一次,然后在每次用户打开应用时跳过它?

And with that approach the tutorial screen is never seen. How can I show it only once on first launch app and then skip it each time user opens the app?

推荐答案

AppDelegatedidFinishLaunchingWithOptions方法中像这样检查NSUserDefaults的值.

In didFinishLaunchingWithOptions method of AppDelegate check for NSUserDefaults value like this way.

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

    let defaults = NSUserDefaults.standardUserDefaults()
    if defaults.objectForKey("isFirstTime") == nil {
         defaults.setObject("No", forKey:"isFirstTime")
         let storyboard = UIStoryboard(name: "main", bundle: nil) //Write your storyboard name
         let viewController = storyboard.instantiateViewControllerWithIdentifier("ViewController") as! ViewController
         self.window.rootViewController = viewController 
         self.window.makeKeyAndVisible()
    }
    return true
}

注意:我已经创建了 ViewController 的对象,你需要创建你的 FirstPage 教程屏幕的对象,然后将它分配给 rootViewController.

Note: I have created the object of ViewController you need to create the object of your FirstPage tutorial screen after that assign it to the rootViewController.

这篇关于如何在第一次运行应用程序(例如教程)期间使 uiviewcontroller 仅可见一次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆