在didReceiveRemoteNotification中加载特定控制器

时间:2013-11-07 11:39:46

标签: ios objective-c uinavigationbar uitabbar

我在我的应用上开发push notification。我希望当人们点击推送消息时,app会打开一个特定的控制器;

如果我这样做:

storyBoardName = @"MyStoryboardName";
UIStoryboard* storyBoard = [UIStoryboard storyboardWithName:storyBoardName bundle:nil];
MainWebController* MainWeb = [storyBoard instantiateViewControllerWithIdentifier:@"MainWeb"];
MainWeb.urlToLoad = URL_TO_LOAD;
self.window.rootViewController = MainWeb;
[self.window makeKeyAndVisible];

有效,我可以看到MainWeb当我点按推按按钮但控制器视图覆盖了所有屏幕:标签栏和导航栏都被隐藏了!

我知道rootviewcontrolleruitabbar

 NSLog(@"Controller: %@",self.window.rootViewController.debugDescription);

2 个答案:

答案 0 :(得分:4)

解决:

UITabBarController *tabController = (UITabBarController *)self.window.rootViewController;

tabController.selectedIndex = 0;

UINavigationController *navigationController = (UINavigationController *)tabController.selectedViewController;
[navigationController pushViewController:MainWeb animated:YES];

答案 1 :(得分:0)

您要将rootViewController设置为MainWebController来替换UIViewController。这是Storyboard中的最初UIViewConroller吗?

从您的问题看,最初的TabViewController似乎是UIViewController,您真正想要的是在此内部设置{{1}}。