ios - 启动时的欢迎屏幕

标签 ios swift2 bwwalkthrough

我想要一种方法让用户在应用程序首次启动时有一个欢迎屏幕/教程。如果这不是应用程序的第一次启动,那么它会像往常一样打开。

如果应用程序正常打开,我已经将欢迎屏幕绑定(bind)到按钮功能。我正在使用 BWWalkThroughViewController。这是我的按钮功能代码:

@IBAction func showWalkThroughButtonPressed() {

    // Get view controllers and build the walkthrough
    let stb = UIStoryboard(name: "MainStoryboard", bundle: nil)
    let walkthrough = stb.instantiateViewControllerWithIdentifier("walk0") as! BWWalkthroughViewController
    let page_one = stb.instantiateViewControllerWithIdentifier("walk1") as UIViewController
    let page_two = stb.instantiateViewControllerWithIdentifier("walk2") as UIViewController
    let page_three = stb.instantiateViewControllerWithIdentifier("walk3") as UIViewController
    let page_four = stb.instantiateViewControllerWithIdentifier("walk4") as UIViewController
    let page_five = stb.instantiateViewControllerWithIdentifier("walk5") as UIViewController

    // Attach the pages to the master
    walkthrough.delegate = self
    walkthrough.addViewController(page_one)
    walkthrough.addViewController(page_two)
    walkthrough.addViewController(page_three)
    walkthrough.addViewController(page_four)
    walkthrough.addViewController(page_five)

    self.presentViewController(walkthrough, animated: true, completion: nil)
}

func walkthroughCloseButtonPressed() {
    self.dismissViewControllerAnimated(true, completion: nil)
}

该代码位于 MyTableViewController.swift 文件中。

这是我想不通的:

我希望 View Controller 在首次启动时显示。用户完成教程后,他们可以按关闭按钮,它就会关闭。我有代码来检查它是否是该应用程序的首次启动。它位于 AppDelegate.swift 文件中。这是代码:

// First Launch Check

    let notFirstLaunch = NSUserDefaults.standardUserDefaults().boolForKey("FirstLaunch")
    if notFirstLaunch {
        print("First launch, setting NSUserDefault")
        NSUserDefaults.standardUserDefaults().setBool(true, forKey: "FirstLaunch")
    }
    else {
        print("Not first launch.")
    }
    return true

那么如何让欢迎屏幕在首次启动时启动?我是否必须在 AppDelegate 中创建一个函数来处理这个问题,如果是这样,我必须做些什么才能使教程成为首次启动的初始 View Controller ?

最佳答案

我相信您需要做的已经在这里涵盖:Programmatically set the initial view controller using Storyboards .如果这对您不起作用,请添加更多关于实现失败原因的注释。在谷歌上搜索“在启动 ios 时以编程方式更改 uiviewcontroller”将产生其他类似的链接。

关于ios - 启动时的欢迎屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34187067/

相关文章:

IOS:如何将UITabbar的位置更改为 View 顶部

ios - 升级到 Xcode 7 后 UIImagePickerControllerMediaURL 上没有文件

ios - 无法在 AudioFileStreamOpen 的 AudioFileStream_PacketsProc 回调中使用 AudioConverterFillComplexBuffer 将 mp3 转换为 PCM

ios - Swift 3 中的计数元素

ios - 如何使用 Swift 3 在 BWWalkthrough View Controller 中添加标签?

ios - 适用于 iOS Swift 的 Google 日历 API

ios - 如何使用 Json 数组到 UITableview

ios - “The application does not have a valid signature” 在 XCode 5 中显示每一秒

ios - 在没有 Storyboard的情况下使用 BWWalkthrough 库,Walkthrough Custom

ios - 具有完整图像背景溢出的 PageViewController