问题描述
我工作的一个项目,一个标签栏控制器和推送通知,当我的应用程序根据收到警报身体就会打开嵌入在标签栏一个确定的视图控制器的推送通知。
我已经可以present视图控制器,但我失去了标签栏。
有关presenting这个视图控制器是我做的:
UIStoryboard *分镜= [UIStoryboard storyboardWithName:@主捆绑:无];
VC5 * IVC = [故事板instantiateViewControllerWithIdentifier:@VC5];
UINavigationController的* navigationController = [[UINavigationController的页头] initWithRootViewController:IVC]
self.window.rootViewController =零;
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible]
我想这code显示标签栏,但我没有工作:
的UITabBarController * tabBarController = [[的UITabBarController页头] initWithNibName:@tabBarController捆绑:无];
tabBarController.selectedViewController = [故事板instantiateViewControllerWithIdentifier:@tabBarController];
tabBarController.selectedViewController =零;
tabBarController.selectedViewController = [tabBarController.viewControllers objectAtIndex:0];
*的UITabBarController =的TabBar(*的UITabBarController)self.window.rootViewController;
[的TabBar的setSelectedIndex:0];
我的故事板由一个初始登录的ViewController这是一个导航控制器里面,在用户登录的提示选择一个城市,然后我present一个标签栏控制器,由O 4片,我需要的视图通过推送通知present是在第一个选项卡,并且是导航控制器内的第五个视图。
我这里看出来的其他问题在SO但没有任何工程,这是我第一次在iOS的发展,任何帮助将是非常美联社preciated。谢谢
编辑:
我也尝试从AppDelegate中做出SEGUE当我收到通知,但我得到这个错误
终止应用程序由于未捕获的异常'NSInvalidArgumentException',原因是:接收器(小于TabBarController:0x16dec150>)与标识符的赛格瑞'pushNotification
这是我的code为推:
TabBarController *的TabBar = [[TabBarController页头] initWithNibName:@tabBarController捆绑:无];
[的TabBar performSegueWithIdentifier:@pushNotification发件人:个体经营];
我解决了这个由presenting视图控制器是标签栏控制器之前,然后执行中间塞格斯编程,直到我达到我需要的视图present给用户,为了这个,我传递一个标志,每个视图和viewWillAppear中的方法进行SEGUE
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];
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.
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
EDIT: 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'
This is my code for the push:
TabBarController *tabBar = [[TabBarController alloc] initWithNibName:@"tabBarController" bundle:nil];
[tabBar performSegueWithIdentifier:@"pushNotification" sender:self];
I resolved this by presenting the view controller that is before the tab bar controller and then perform the intermediate segues programatically till i reach the view i need to present to the user, for this i pass a flag to each view and perform the segue in the viewWillAppear method
这篇关于如何接收推送通知时present嵌在标签栏控制器,导航控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!