2016-09-01 10 views
1

私はRootVCを持っています。それはSwipeViewController: UINavigationControllerです。 WelcomeNavigationControllerSwift /新しいルートビューコントローラを設定(ロード)する方法

SwipeViewController

、私は条件をチェックしています。その条件が真であれば、私はRootVCを開きたい。

class WelcomeNavigationController: UINavigationController { 

override func viewWillAppear(animated: Bool) { 
     backendless.userService.setStayLoggedIn(true) 

    if backendless.userService.currentUser != nil { 

     print("currentUser != nil") 

     dispatch_async(dispatch_get_main_queue()) { 

      let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate 
      appDelegate.window = UIWindow(frame: UIScreen.mainScreen().bounds) 
      let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil) 
      let vc : RootVC = storyboard.instantiateViewControllerWithIdentifier("RootVC") as! RootVC 
      appDelegate.window?.rootViewController = vc 
      appDelegate.window?.makeKeyAndVisible() 

     } 
    } 
} 

print文が実行され、私のRootVCのいくつかの印刷文も実行されます。理論的にはRootVCが読み込まれます。しかし、それは見えません。自分のRootVCを見えるようにするにはどうすればいいですか?

ヘルプは大歓迎です。

答えて

2

私はあなたが現在のビューコントローラ

self.addChildViewController(vc) 
vc.view.frame = self.view.frame 
self.view.addSubview(vc.view) 
vc.didMoveToParentViewController(self) 
+0

'vc.didMoveToParentViewControllerにrootVCを追加する必要があると思う:self'はエラーをスロー=予想される表現 –

+0

'(自己)は 'それを解決しました。しかし、それは私のためには機能しません。以前と同じですが、上に白のナビゲーションバーがあります。 「古い」ビューは固定されているようです。そして、私の 'RootVC'のprintステートメントが実行されます。 –

+0

ああ、この場合私の実験。あなたはwelcomeViewController - > rootVCからプッシュする必要があります。 その後、navigationController.viewControllerのwelcomeVCを削除します。 rootVCをrootViewControllerに設定してください – Giang

関連する問題