0

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

我在 AppDelegate 中的 didFinishLaunchingWithOptions 和 didReceiveLocalNotification 中调用此方法,以便当应用程序处于后台时,通过单击通知栏应用程序导航到适当的表格视图。

4

2 回答 2

0

UILocalNotification有一个userInfo字典。在那里,您可以存储该通知的一些相关信息,在您的情况下为 indexPath

  NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:selectedSymptomIndex,@"selectedSymptomIndex",keyIndexNumber,@"keyIndexNumber", nil];
localNotification.userInfo = userInfo;  

在接收通知时(在 didReceiveLocalNotification 中),您可以检索 userInfo 字典,如notification.userInfo. 从中您将获得 selectedSymptomIndex 和 keyIndexNumber。
现在您可以构造 indexPath

NSIndexPath *selectedSymptIP = [NSIndexPath indexPathForRow:selectedSymptomIndex inSection:keyIndexNumber]; 
于 2013-05-20T12:42:59.610 回答
0

请打印您的用户信息,看看里面有什么。它将是一本字典,并且可能遗漏了某些内容或包含任何 nil 值。

于 2013-05-20T12:45:41.403 回答