第一次启动的PageViewController(应用程序演示)然后是tabBarViewController,Swift

时间:2016-02-04 19:42:44

标签: swift uitabbarcontroller nsuserdefaults uipageviewcontroller


我有一个带有3个视图的 PageViewController 来展示应用程序,在最后一页我有一个与我的 TabBarViewController 链接的按钮。
我想只有第一次发布,我的3个演示视图,然后是下次启动,直接用我的TabBarViewController启动。

我该怎么做? 的由于!!!

1 个答案:

答案 0 :(得分:0)

修改

tabBarController:

 required init(coder aDecoder: NSCoder)
  {
      super.init(coder: aDecoder)!
  }

页面视图和tabBar之间的按钮:

@IBAction func firstTime() {

    NSUserDefaults.standardUserDefaults().setBool(true, forKey: "hasAppBeenLaunchedBefore")
    print(true)

}

AppDelegate:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

    // Override point for customization after application launch.

    didFinishLaunchingOnce()


    return true
}

func didFinishLaunchingOnce() -> Bool
{
    let defaults = NSUserDefaults.standardUserDefaults()

    if let hasBeenLauncherBefore = defaults.stringForKey("hasAppBeenLaunchedBefore")
    {
        self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
        let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
        var exampleViewController: TabBarViewController = mainStoryboard.instantiateViewControllerWithIdentifier("TabBarViewController") as! TabBarViewController

        self.window?.rootViewController = exampleViewController

        self.window?.makeKeyAndVisible()
        //print(" N-th time app launched ")
        return true
    }
    else
    {
        self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
        let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
        var exampleViewController: OnboardingPager = mainStoryboard.instantiateViewControllerWithIdentifier("OnboardingPager") as! OnboardingPager

        self.window?.rootViewController = exampleViewController

        self.window?.makeKeyAndVisible()
        //print(" First time app launched ")
        defaults.setBool(true, forKey: "hasAppBeenLaunchedBefore")
        return false
    }
}

<强>享受