如何在接收推送通知时呈现嵌入在标签栏控制器中的导航控制器 [英] how to present a navigation controller embedded in a tab bar controller when receiving a push notification
问题描述
我正在开发一个带有标签栏控制器和推送通知的项目,当我的应用根据警报正文收到推送通知时,它将打开一个嵌入在标签栏中的确定视图控制器.
I'm working on a project with a tab bar controller and push notifications, when my app receives a push notifications depending of the alert body it will open a determinate view controller that is embedded in tab bar.
我已经可以展示视图控制器,但我丢失了标签栏.
I already can present the view controller but i lost the tab bar.
为了呈现视图控制器,这就是我所做的:
For presenting the view controller this is what i do:
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];
我试过这段代码来显示标签栏,但我没有工作:
I tried this code to show the tab bar but i didn't work:
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 包含一个位于导航控制器内的初始登录 ViewController,在用户登录后会提示选择一个城市,然后我呈现一个包含 4 个选项卡的选项卡栏控制器,我需要通过该视图呈现推送通知位于第一个选项卡中,是导航控制器中的第五个视图.
My Storyboard consists of an Initial Login ViewController that is inside a navigation controller, after the user logins is prompt to pick a city and then i present a tab bar controller that consists o 4 tabs, the view that i need to present via push notification is in the first tab and is the fifth view inside that navigation controller.
我在这里查看了其他问题,但没有任何效果,这是我第一次在 iOS 中开发,任何帮助将不胜感激.谢谢
I look out other questions here in SO but nothing works, this is the first time i develop in iOS, any help would be highly appreciated. thank you
当我收到通知时,我也尝试从 AppDelegate 进行 segue,但我收到此错误
I also try to make a segue from the AppDelegate when i receive the notification but i get this error
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];
推荐答案
我通过在通知到达时呈现视图控制器并将必要的数据传递给视图控制器来解决此问题
I resolved this by presenting the view controller when the notification arrives and pass the necessary data to the view controller
这篇关于如何在接收推送通知时呈现嵌入在标签栏控制器中的导航控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!