【发布时间】:2014-04-28 17:00:18
【问题描述】:
我正在开发一个带有标签栏控制器和推送通知的项目,当我的应用根据警报正文收到推送通知时,它将打开一个嵌入标签栏的确定视图控制器。
我已经可以展示视图控制器,但我丢失了标签栏。
为了呈现视图控制器,这就是我所做的:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
vc5 *ivc = [storyboard instantiateViewControllerWithIdentifier:@"vc5"];
UINavigationController *navigationController=[[UINavigationController alloc] initWithRootViewController:ivc];
self.window.rootViewController =nil;
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
我尝试了这段代码来显示标签栏,但我没有工作:
UITabBarController *tabBarController = [[UITabBarController alloc] initWithNibName:@"tabBarController" bundle:nil];
tabBarController.selectedViewController = [storyboard instantiateViewControllerWithIdentifier:@"tabBarController"];
tabBarController.selectedViewController = nil;
tabBarController.selectedViewController = [tabBarController.viewControllers objectAtIndex:0];
UITabBarController *tabBar = (UITabBarController *)self.window.rootViewController;
[tabBar setSelectedIndex:0];
我的 Storyboard 包含一个位于导航控制器内的 Initial Login ViewController,在用户登录后提示选择一个城市,然后我呈现一个包含 o 4 个选项卡的选项卡栏控制器,我需要通过推送通知位于第一个选项卡中,是该导航控制器内的第五个视图。
我在 SO 中查看了其他问题,但没有任何效果,这是我第一次在 iOS 中开发,任何帮助将不胜感激。谢谢
编辑: 当我收到通知时,我也尝试从 AppDelegate 进行 segue,但我收到此错误
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<TabBarController: 0x16dec150>) has no segue with identifier 'pushNotification'
这是我的推送代码:
TabBarController *tabBar = [[TabBarController alloc] initWithNibName:@"tabBarController" bundle:nil];
[tabBar performSegueWithIdentifier:@"pushNotification" sender:self];
【问题讨论】:
-
如果您使用的是故事板,为什么您要尝试从代码加载 tabbarcontroller。 segue 会为你做的。
-
@pawan 看到我编辑的问题,我也尝试从 AppDelegate 执行 segue,但我认为这是不可能的,或者我无法让它工作,谢谢
-
你找到答案了吗?
-
你找到答案了吗?
-
@ChandanAnand 我最终将它呈现为模态,产品要求发生了变化
标签: ios objective-c uitabbarcontroller apple-push-notifications