OGeek|极客世界-中国程序员成长平台

标题: objective-c - 取消选择RowAtIndexPath : failing in iOS5 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 09:28
标题: objective-c - 取消选择RowAtIndexPath : failing in iOS5

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

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

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

其实到时候

 - (void)viewDidDisappearBOOL)animated

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

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

编辑: 它被定义为

currentCellIndex = indexPath;   

来自

-(void) displaySubViewUITableView *)tableView indexPathNSIndexPath *)indexPath

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

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

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

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



Best Answer-推荐答案


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

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

您需要在“父” View Controller 中实现这一点,其中声明了 mainTable

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

关于objective-c - 取消选择RowAtIndexPath : failing in iOS5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7816962/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4