0

我有一个应用程序,当通知被触发时,当应用程序处于后台时,我会得到一个通知栏,当我点击该栏时,它会导航到通知集的表格视图。当我从后台退出应用程序时,我收到了通知,但是当点击通知栏时,应用程序崩溃了,因为它没有获取 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];

}
4

2 回答 2

0

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

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

于 2013-05-21T17:26:48.360 回答
0

我能够解决问题。由于加载了错误的 xib 文件,因此发生了崩溃。

于 2013-05-29T15:48:22.067 回答