调用didFinishLaunchingWithOptions时应用程序崩溃

时间:2013-05-21 16:15:22

标签: iphone ios objective-c xcode uitableview

我有一个应用程序,当通知被触发时,当应用程序处于后台时,我会收到通知栏,当我点击该栏时,它会导航到通知集的表格视图中。当我从后台退出应用程序时,我收到通知但是当点击通知栏时,应用程序正在崩溃,因为它没有获得tableview的索引路径。

当应用在后台退出并重新加载应用时,请输入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];

}

2 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分:0)

我能够解决问题..因为加载了错误的xib文件后发生了崩溃。