2016-12-13 14 views
1

私はUITabbarとビュー階層に基づいてアプリケーションを次のように開発しています。UITabBarControllerとUINavigationControllerからUIViewControllerにアクセス

UITabBarController ----> UINavigationController ---->のUIViewController

私は特定のUIViewControllerを開きますプッシュ通知ペイロードを持って、私は明示的に開いているのUIViewController直接ビューコントローラのストーリーボードのIDを使用してできますが、タブバーとナビゲーションバー「を受賞tショー。 特定のView Controllerにアクセスし、AppDelegate didReceiveRemoteNotificationsからTabBarとNavControllerを表示するにはどうすればいいですか?

ありがとう!

+0

をあなたは私の答えをチェックしてもらえますか? –

+0

確かに、私はあなたのためにもう少し質問があります@FedericoMalagoni – chronycles

答えて

1

あなたのVCのすべてのインスタンスを作成する必要があり、彼の前任者のルートとしてそれらのすべてを設定します。

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 

    let mainStoryboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil) 
    let yourVC = mainStoryboard.instantiateViewControllerWithIdentifier("YourVC_Identifier"); 
    let yourNavController = mainStoryboard.instantiateViewControllerWithIdentifier("YourNAV_Identifier") as! UINavigationController 
    let yourTabController = mainStoryboard.instantiateViewControllerWithIdentifier("YourTAB_Identifier") as! UITabBarController 

    yourNavController.setViewControllers([yourVC], animated: false) 
    yourTabController.setViewControllers([yourNavController], animated: false) 


    self.window = UIWindow(frame: UIScreen.mainScreen().bounds) 
    self.window?.rootViewController = yourTabController 
    self.window?.makeKeyAndVisible() 



    return true 
} 
+0

こんにちは@Federico Malagoni、あなたの答えは素晴らしいです、コードは私が期待したように動作しますが、私はVCが開始された後popToRootViewControllerを使用することはできませんようです。何故ですか? – chronycles

+0

私はあなたの質問を理解しませんでした。新しい質問を作成できますか? –

0

[[UIApplication sharedApplication] keyWindow]の属性は.rootViewControllerです。おそらくそれはあなたのタブバーです。このコントローラでは、アクティブなタブを設定し、.viewControllersプロパティを持つビューコントローラを切り替えることができます。今度は、あなたのUINavigationControllerには、.rootViewControllerというプロパティがあるはずです。ストーリーボードからインスタンシエートして、ルートを設定するか、ナビゲーションコントローラの上にView Controllerを押します。

+0

迅速に擬似コードを表示できますか?ありがとうございました – chronycles

0

は、プログラムのApp代理人からの階層に従ってください。 エントリポイントがストーリーボードの場合、をAppDelegateに設定して、UITabBarControllerを次のように設定できます。

//self.tabBarController is you TabBar from Storyboard, or programatically initialized 
self.window.rootViewController = self.tabBarController; 

その後、あなたはタイプによってdidReceiveRemoteNotificationsソートに通知し、通知を持っている、とビューコントローラを見つけるたび:

//Let's say the View Controller being accessed is in the first position of the stack of viewcontroller from UITabBarController & UINavigationController 
UINavigationController *navViewController = self.tabBarController.viewControllers.firstObject; 
UIViewController *accessedViewController = navViewController.viewcontroller.firstObject; 
関連する問題