2015-12-09 96 views
3

我想讓用戶在首次啓動應用程序時獲得歡迎屏幕/教程。如果它不是該應用的首次發佈,那麼它將像往常一樣開放。啓動時的歡迎屏幕

如果應用程序正常打開,我已將歡迎屏幕綁定到按鈕功能。我正在使用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中創建一個函數來處理這個問題,如果有的話,我需要做些什麼才能使該教程成爲第一次啓動時的初始視圖控制器?

回答