【发布时间】:2011-01-26 22:10:04
【问题描述】:
我有一个 UITableView,当在一行上调用 didSelectRowAtIndexPath 时,它完美地切换到下一个视图。但是,当我单击“后退”按钮,然后选择之前选择的同一行时……我的应用程序崩溃了。如果我选择不同的行,它不会崩溃。代码如下:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary *tempEventDictionary = [[NSDictionary alloc]initWithDictionary:[arrayWithEvents objectAtIndex:indexPath.row]];
NSLog(@"%i",tempEventDictionary);
//push to new view and set myArray in the cardPage
CardPageViewController *cardPageViewController = [[CardPageViewController alloc] init];
cardPageViewController.eventDictionary = tempEventDictionary;
[self presentModalViewController:cardPageViewController animated:YES];
[cardPageViewController release];
[tempEventDictionary release];
}
“EXC_BAD_ACCESS” 消息崩溃。
如您所见,我正在打印 NSDictionary 的指针地址,它似乎正在为每个单独的 indexPath.row 寻找相同的地址。这意味着指针位置正在被释放,当我尝试将其重新分配为相同 indexPath.row 的值时,正在搜索旧的指针地址,但它不存在。也许我在这里完全错了。任何帮助表示赞赏。
【问题讨论】:
-
崩溃的输出是什么?
-
没有输出。只是一个崩溃。我想有一次我试图让我的字典自动释放时看到了 malloc 的东西。
-
当然有一些输出。检查 gdb 控制台并粘贴最后一条消息。另外,为什么要使用 int 格式说明符 ("%i") 打印 NSDictionary?
-
我正在使用 int 格式打印以查看指针位置。我的控制台中没有崩溃的输出,只有从我的 NSLogs 打印的值。
-
抱歉,收到“EXC_BAD_ACCESS”消息。
标签: iphone memory uitableview