【问题标题】:deselectRowAtIndexPath: failing in iOS5deselectRowAtIndexPath:在 iOS5 中失败
【发布时间】:2011-10-20 15:40:08
【问题描述】:

以下在 iOS 4.3 中运行良好,但在 iOS5 中抛出 EXC_BAD_ACCESS。

if(mainTable != nil){
    [mainTable deselectRowAtIndexPath:currentIndexPath animated:YES];

mainTable 是 UITableView 类型。它在带有 deselectRowAtIndexPath: 的行上失败。离开主(第一个)表视图时会发生上述异常。步骤是: 在主表视图中单击一行。另一个表视图显示。单击左上角按钮返回主表并发生异常。

其实到时候

 - (void)viewDidDisappear:(BOOL)animated

被断点命中,currentIndexPath 已在 iOS5 中发布。

我可以在这里寻找什么?我知道 iOS5 在释放对象方面做了一些不同的事情。也许我可以做一些额外的检查,但我不确定从哪里开始。

编辑: 它被定义为

currentCellIndex = indexPath;   

来自

-(void) displaySubView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath

我确实在我的方案的运行部分启用了僵尸,现在获取详细信息。当我点击上述行时,我在控制台中看到:

*** -[NSIndexPath isEqual:]: message sent to deallocated instance 0x85a2010

为什么在 iOS5 而不是 iOS 4.3 中会发生这种情况?我在 currentIndexPath 的 dealloc 中确实有一个断点,并且它永远不会被命中。

我开始相信这与 ARC 有关。我仍然有很多保留/释放。我不想为 ARC 做自动格式化,因为那会导致更多问题。我确实尝试了用于在每个文件的基础上禁用 ARC 的标志。这只是用未知命令引发了编译器错误。

【问题讨论】:

标签: objective-c ios memory-management xcode4


【解决方案1】:

这不是您问题的确切答案,但您可能需要考虑取消选择 viewWillAppear 中的行:

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [mainTable deselectRowAtIndexPath:[mainTable indexPathForSelectedRow] animated:YES];
}

您需要在声明了mainTable 的“父”视图控制器中实现这一点。

关于您的实际问题,您能告诉我们您的@property 是如何查找currentCellIndex 的吗?

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-18
  • 1970-01-01
  • 1970-01-01
  • 2011-12-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多