2013-02-04 86 views
1

我搜索了互联网和堆栈溢出,仍然无法解决这个问题。从appDelegate pushViewController - 问题

这是一个选项卡式应用程序模板。

当应用程序没有运行,并且它收到一个推送通知我想从

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions我通过解析JSON数据等做阅读launchOptions的内容...

那么我想在故事板上的单独视图上显示。

我读过一些帖子的事:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; DetailViewController *ivc = [storyboard instantiateViewControllerWithIdentifier:@"Detail"]; [(UINavigationController*)self.window.rootViewController pushViewController:ivc animated:NO];

但是这是给我

*终止应用程序由于未捕获的异常 'NSInvalidArgumentException',原因:' - [的UITabBarController pushViewController:动画:]:无法识别的选择发送到实例0x1c5a0c20'

当应用程序在后台运行,并从

- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)notification接收推我叫[[NSNotificationCenter defaultCenter] postNotificationName:@"receivedPushNotification" object:self];

告诉任何视图当前正在显示

detail = [self.storyboard instantiateViewControllerWithIdentifier:@"Detail"]; [self.navigationController pushViewController:detail animated:YES];

工作正常。

的问题是,当应用程序第一次启动,所以我需要把细节视图控制器上的用户的方式,从的appDelegate画面无的这些观点被加载。

由于

回答

0

我想你的故事板被设置为“mainstoryboard”(键UIMainStoryboardFile在你的Info.plist)。在这种情况下,的UIKit将加载故事板并设定其初始的ViewController作为窗口的根视图控制器在发送应用程序之前:didFinishLaunchingWithOptions:发送到您的AppDelegate.I还假定故事板中的初始viewcontroller是导航控制器,您要在其上推送您的主或loginview控制器。

你可以问你的窗口,它的根视图控制器,并发送performSegueWithIdentifier:发件人:消息吧:

NSString *segueId = success ? @"pushMain" : @"pushLogin"; 
[self.window.rootViewController performSegueWithIdentifier:segueId sender:self];