【发布时间】:2014-09-22 13:13:00
【问题描述】:
在新发布的 iOS8 中,我的 TableView 出现了以前没有的崩溃。
我使用以下代码来计算单元格高度。这在 iOS7 上运行良好,但在 iOS8 上崩溃。
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
cell.frame = CGRectMake(0, 0, tableView.frame.size.width, 0);
[cell setNeedsUpdateConstraints];
[cell updateConstraintsIfNeeded];
CGFloat height = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
return height + 1;
}
*** -[UITableViewCell release]: 消息发送到释放的实例 0x7d2e2bb0
发生此崩溃时,我得到以下 Stacktrace:(抱歉,无法从 AppCode 中复制文本)
这是 Instruments 的输出...
以前有没有人见过这种行为,或者知道如何防止这种崩溃?
【问题讨论】:
-
只要 po 0x7d2e2bb0 你就会知道哪个对象在被释放后正在被访问。也启用僵尸然后你可以轻松调试。简而言之,一个对象被释放并且你试图访问它。
-
嘿walle84:我已经启用了僵尸,谢谢。我的猜测是 AutoreleasePool 释放了 Cell,后来被 [tableView dequeReusableCell ...] 使用。但是如何防止 AutoreleasePool 释放单元格?
-
我将您的 heightForRowAtIndexPath 方法代码添加到了我的 sampleDemo 中,该方法没有发生崩溃。你应该通过调试和获取错误点再次检查。
标签: ios objective-c uitableview nsautoreleasepool