deselectRowAtIndexPath:在 iOS5 中失败
以下代码在 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 的标志。这只是引发了未知命令的编译器错误。
The following works fine in iOS 4.3 but throws a EXC_BAD_ACCESS in iOS5.
if(mainTable != nil){
[mainTable deselectRowAtIndexPath:currentIndexPath animated:YES];
mainTable is of type UITableView. It fails on the row with deselectRowAtIndexPath:. The above exception occurs when leaving the main (first) table view. The steps are: Click a row from main table view. Another table view displays. Click top left button to go back to the main table and exception occurs.
Actually, by the time
- (void)viewDidDisappear:(BOOL)animated
is hit via breakpoint, currentIndexPath is already released in iOS5.
What can I look for here? I know iOS5 does some different things with releasing objects. Perhaps there are some additional checks I can do but I'm not sure where to start.
EDIT:
It is defined as
currentCellIndex = indexPath;
and comes from
-(void) displaySubView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath
I do have zombies enabled in the Run part of my scheme and now get the details. When I hit the above line, I see in the console:
*** -[NSIndexPath isEqual:]: message sent to deallocated instance 0x85a2010
Why does that happen in iOS5 and not in iOS 4.3? I do have a breakpoint in the dealloc on currentIndexPath and it is never hit.
I'm starting to believe this is related to ARC. I still have lots of retains/releases. I don't want to do the auto format for ARC since that is to cause more problems. I did try the flag used to disable ARC on a per file basis. That just threw a compiler error with unknown command.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不是您问题的准确答案,但您可能需要考虑取消选择
viewWillAppear
中的行:您需要在“父”视图控制器中实现此操作,其中
mainTable
已声明。关于您的实际问题,您能告诉我们您的
@property
如何查找currentCellIndex
吗?This is not an exact answer to your question, but you might want to consider deselecting your row in
viewWillAppear
:You need to implement this in the 'parent' view controller, where
mainTable
is declared.Regarding your actual question, can you tell us how does your
@property
look forcurrentCellIndex
?