2017-02-05 7 views
0

アプリの最初の起動時に、ストーリーボードに最初のビューコントローラーを表示するコードがいくつかあります。その後、そのページをスキップして、各起動時に2つ目のビューに直接移動します。私は最初のビュー(2番目のビューに接続されている)をナビゲーションコントローラに埋め込んでいます。ナビゲーションコントローラーで最初に起動したときにのみスクロール表示

私の問題は、最初の起動後にアプリケーションが2番目のビューに直接行くときに、ナビゲーションバーが表示されていないビューが上に表示されていることです。私appdelegateで

func firstLaunchCheck(){ 
     let launchedBefore = UserDefaults.standard.bool(forKey: "launchedBefore") 
    if launchedBefore{ 
     let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil) 
     let initialView : UIViewController = storyboard.instantiateViewController(withIdentifier: "mainScreen") as UIViewController 
     self.window = UIWindow(frame: UIScreen.main.bounds) 
     self.window?.rootViewController = initialView 
     self.window?.makeKeyAndVisible() 

    } 
    else{ 

     UserDefaults.standard.set(true, forKey: "launchedBefore") 
    } 

} 

UPDATE: 私はちょうどそれが私には意味がありませんでしたので、(最初のものを除く)ナビゲーションコントローラに埋め込まれたコントローラを表示変更巻き上げそれを持ってください。だから今、それは

+0

は、ナビゲーションコントローラに埋め込む必要があり、あなたの中に第二は、その最上位のVC VC2あるナビゲーションコントローラに行く必要があります。 – aircraft

+0

です。これは、ナビゲーションバーを持つ最初のView Controllerを2度目にスキップするためです。もう一度ナビゲーションバーを表示する場合は、2番目のビューコントローラにも追加する必要があります – Ram

答えて

0

SecondViewControllerUINavigationController階層に追加されていないナビゲーションコントローラをロードする最初の打ち上げ後launchedBeforeが

let storyboard = UIStoryboard(name: "Main", bundle: nil) 
let secondVC = storyboard.instantiateViewController(withIdentifier: "SecondViewController") as! SecondViewController 
let navigationController = window.rootViewController as! UINavigationController 
navigationController?.pushViewController(secondVC, animated: false) 
0

appDelegateで偽であれば、あなたはfirstVCにSecondViewControllerをプッシュできnavigationBar上に確認しますUINavigationControllerに2番目のビューコントローラ、つまり "mainScreen"を埋め込み、それをアプリケーションウィンドウのrootViewControllerにする必要があります。 VC2 @jcka

let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil) 
let navigationController = UINavigationController.init(rootViewController: storyboard.instantiateViewController(withIdentifier: "mainScreen")) 
self.window = UIWindow(frame: UIScreen.main.bounds) 
self.window?.rootViewController = initialView 
self.window?.makeKeyAndVisible() 
関連する問題