启动时欢迎屏幕

时间:2015-12-09 19:11:28

标签: ios swift2 bwwalkthrough

我希望用户能够在首次启动应用时获得欢迎屏幕/教程。如果它不是第一次启动应用程序,那么它会像往常一样打开。

如果应用程序正常打开,我已经将欢迎屏幕绑定到按钮功能。我正在使用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文件中。

这是我无法弄清楚的:

我希望视图控制器在首次启动时显示。用户完成教程后,可以按“关闭”按钮关闭。我有代码来检查它是否是应用程序的首次启动。它位于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中创建一个函数来处理它,如果是这样,我必须做什么才能使教程成为第一次启动时的初始视图控制器?

1 个答案:

答案 0 :(得分:4)

我相信你需要做的事情已在这里介绍:Programmatically set the initial view controller using Storyboards。如果这对您不起作用,请添加有关实施失败原因的更多说明。谷歌搜索“在启动ios上以编程方式更改uiviewcontroller”将产生其他类似的链接。

相关问题