接收推送通知时,转到tabbarcontroller中的某个选项卡

时间:2014-05-22 07:27:14

标签: ios objective-c storyboard

我有以下storyboard enter image description here

我现在想要的是,当我得到push notification时,我应该转到tabbarController内的某个标签页。

我现在想知道实现这一目标的最佳做法是什么? 我可以将self.window.rootController设置为正确的ViewController但是当用户按下注销时我遇到了问题。当他按下注销时,他应该被重定向到第一个ViewController。你最左边看到的那个。

有人可以帮我这个吗?

由于

1 个答案:

答案 0 :(得分:1)

试试这个:

 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
    {


       if (self.window.rootViewController.presentedViewController != nil)
            {
            [self.window.rootViewController.presentedViewController dismissViewControllerAnimated:YES completion:^{

                {
                    UIStoryboard *storyboard=[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
                    tabbarcontroller=[storyboard instantiateViewControllerWithIdentifier:@"Tabbar"];
                    [tabbarcontroller setSelectedIndex:1];
                    [self.window.rootViewController presentViewController:tabbarcontroller animated:YES completion:nil];

                }
                UIStoryboard *storyboard=[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
                tabbarcontroller=[storyboard instantiateViewControllerWithIdentifier:@"Tabbar"];
                  [tabbarcontroller setSelectedIndex:1];
                [self.window.rootViewController presentViewController:tabbarcontroller animated:YES completion:nil];
            }];

                UIStoryboard *storyboard=[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
                tabbarcontroller=[storyboard instantiateViewControllerWithIdentifier:@"Tabbar"];
                [tabbarcontroller setSelectedIndex:1];
                [self.window.rootViewController presentViewController:tabbarcontroller animated:YES completion:nil];
        }