当didFinishLaunchingWithOptions被调用时,应用程序崩溃

我有一个应用程序,当通知被解雇时,我得到一个通知栏,当应用程序在后台,当我点击该栏,导航到通知集的桌面视图。 当我从后台退出应用程序时,我收到通知,但是当点击通知栏时,应用程序由于没有获取tableview的indexpath而崩溃。

当应用程序在后台退出,重新加载应用程序应进入didfinishlaunching。

在appDidFinishLaunching我打电话进入tableview的方法

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.viewController = [[PPViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil] ; UILocalNotification *notification = [launchOptions objectForKey: UIApplicationLaunchOptionsLocalNotificationKey]; if (notification) { int remedyID = [[notification.userInfo objectForKey:kRemindMeNotificationRemedyIDKey] intValue]; NSDictionary *reminderDetails =[NSDictionary dictionaryWithObjectsAndKeys:notification.userInfo,@"kRemindMeNotificationDataKey",[NSNumber numberWithInt:remedyID],kRemindMeNotificationRemedyIDKey,nil]; [_viewController goToReminder:reminderDetails showNotification:YES]; } [application setStatusBarStyle:UIStatusBarStyleBlackTranslucent]; self.viewController = [[PPViewController alloc] initWithNibName:@"PPViewController" bundle:nil]; self.window.rootViewController = self.viewController; [self.window makeKeyAndVisible]; return YES; } **This is the code which navigates into tableview in another viewcontroller** - (void)goToReminder:(NSMutableDictionary *)reminderDictionary showNotification:(BOOL)shouldShowNotification { NSIndexPath *selectedSymptIP = [NSIndexPath indexPathForRow:selectedSymptomIndex inSection:keyIndexNumber]; [self tableView:symptomsTableView didSelectRowAtIndexPath:selectedSymptIP]; } 

当你退出应用程序,你的应用程序再次启动,您的viewController尚未设置。 从通知启动时,您需要检查您是从后台恢复,还是正常启动。

查看UIApplicationDelegate协议参考中的applicationWillEnterForegroundapplicationDidBecomeActive ,了解如何处理从各种状态恢复应用程序。 另请参阅: http : //developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html#//apple_ref/doc/uid/TP40007072-CH4-SW3

我能够解决这个问题..崩溃发生,因为错误的xib文件被加载。