我正在尝试实施didReceiveRemoteNotification
方法。当我收到推送通知时,我想显示一个特定的视图。我的应用使用UITabbarController
作为根视图控制器,UINavigationController
作为其子级:
这是我的appdelegate:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
UINavigationController *navController = (UINavigationController *)[[((UITabBarController *)self.window.rootViewController) viewControllers] objectAtIndex:2];
NSString * storyboardName = @"others";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"BusinessAccountView"];
[navController pushViewController:vc animated:YES];
[PFPush handlePush:userInfo];
}
不幸的是,代码不起作用。如果我将[navController pushViewController:vc animated:YES]
更改为[navController presentViewController:vc animated:YES]
,它会有效,但我会丢失导航栏。
有没有人知道如何做到这一点?
答案 0 :(得分:0)
按照本教程(故事板教程:创建标签栏控制器和Web视图)....
http://www.appcoda.com/storyboard-tutorial-create-tab-bar-controller-and-web-view/
答案 1 :(得分:0)
这是一个逐步的解决方案。
setSelectedIndex
或setSelectedViewController
选择该标签。rootViewController
(您的UINavigationController
)。示例代码:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
UITabBarController* tabController = self.window.rootViewController;
if (tabController.selectedIndex != 2) [tabController setSelectedIndex:2];
UINavigationController *navController = tabController.selectedViewController;
NSString * storyboardName = @"others";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"BusinessAccountView"];
[navController pushViewController:vc animated:YES];
[PFPush handlePush:userInfo];
}