2016-07-30 57 views
-1

我的工作有兩個故事板的應用:一爲我的應用程序的入職控制器和其他爲我的主要應用程序。我的入門視圖控制器有一個跳過按鈕,當按下時,用戶將指示主要故事板。只要用戶沒有點擊跳過按鈕,我只想顯示入職視圖。一旦跳過按鈕,相應的故事板應該永久消失。如何永遠隱藏Storyboard/ViewControllers?

我以爲我可以解決這個問題,只是在應用程序第一次打開時顯示入門故事板,我發現一些代碼在線,似乎有幫助,但它不工作......這裏是代碼我的應用程序的的AppDelegate:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 
    // Override point for customization after application launch. 

    FIRApp.configure() 
    Fabric.with([Crashlytics.self]) 

    let defaults = NSUserDefaults.standardUserDefaults() 
    if (defaults.objectForKey("userAsLoggedInBefore") != nil) { 

     print("Functions") 

     //here you insert the code to go to the main screen 
     var mainView: UIStoryboard! 
     mainView = UIStoryboard(name: "Functions", bundle: nil) 
     let viewcontroller : UIViewController = mainView.instantiateViewControllerWithIdentifier("functions") as UIViewController 
     self.window!.rootViewController = viewcontroller 

    } else { 

     //this means the user hasn't logged in before and you can redirect him to the onboarding page 
     print("Onboarding") 

     var mainView: UIStoryboard! 
     mainView = UIStoryboard(name: "Main", bundle: nil) 
     let viewcontroller : UIViewController = mainView.instantiateViewControllerWithIdentifier("onboarding") as UIViewController 
     self.window!.rootViewController = viewcontroller 

    } 
} 

注意,在我的代碼「主」是新手上路的故事板,而「功能」是我主要的應用程序代碼。

但是這個代碼不工作的打算作爲我同樣的問題依然出現。如果有人可以看看我的代碼,看看我是否做錯了,那將不勝感激。

在此先感謝!

回答

1

你永遠寫NSUser默認值。因此,它會留零..

你缺少一些線這樣的:

let defaults = NSUserDefaults.standardUserDefaults() 
    defaults.setValue("Did watch", forKey: "userAsLoggedInBefore") 

把它在最後,如果 - else語句

+0

感謝了很多人! –