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

标签 ios objective-c storyboard

我有以下 Storyboard enter image description here

我现在想要的是,当我收到一个推送通知 时,我应该转到我的tabbarController 中的某个选项卡。

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

有人可以帮我吗?

谢谢

最佳答案

试试这个:

 - (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];
        }

关于ios - 收到推送通知时转到 tabbarcontroller 中的某个选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23800342/

相关文章:

ios - ASP.NET 到移动设备

ios - 翻转过渡 UINavigationController 推送在动画完成之前不会调用 viewDidLoad

ios - objective-c 文本字段 : selectAll text doesn't always work

ios - 在 Storyboard iOS 中隐藏导航栏的后退按钮

ios - 如何在导航栏顶部添加 View

javascript - 图像加载事件未在 iPhone (IOS) 上触发

iOS RunLoop 和 DispatchQueue.main.async

ios - 在 self.tableView.reloadData() 上展开 Optional 值时意外发现 nil

ios - 图表数据的核心数据模型设计

Wpf:Storyboard.TargetName 有效,但 Setter TargetName 无效