2016-07-30 5 views
-1

私は2つのストーリーボードを持つアプリケーションに取り組んでいます:1つは私のアプリケーションのオンボードコントローラ用で、もう1つはメインアプリケーション用です。私のオンボーディング・ビュー・コントローラーにはスキップ・ボタンがあり、これを押すとメイン・ストーリーボードにユーザーが誘導されます。ユーザーがスキップボタンを押していない限り、オンボーディングビューを表示したいだけです。スキップボタンがヒットすると、対応するストーリーボードは永遠に消えるはずです。ストーリーボード/ 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のデフォルトには書き込みません。 else文

+0

おかげでたくさんの人を - 場合の最後にそれを入れて

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

:だから、あなたは、このようないくつかの行がありません

.. nilをご利用いただけます! –