使用insertRowAtIndexPath调整UITableViewCell高度

时间:2013-01-08 22:28:21

标签: ios xcode cocoa-touch uitableview

我有一张桌子,当用户点击一个单元格时,一个细节单元格在其下方垂下。我已经弄清楚如何使用insertRowAtIndexPath来实现这一点,但是细节单元的行高比普通单元高。我已经尝试了heightForRowAtIndexPath,但只是在初始加载视图时(或使用reloadData)才会调用它。但是,我不希望将详细信息单元格添加到表格视图的数据中,从而消除了reloadData的可能性,因此heightForRowAtIndexPathUITableViewCell。我的自定义ItemDetailCell子类为cellForRowAtIndexPath。我认为这可能会加载故事板中关联单元格的指定行高,但这似乎不起作用。这就是我在if (indexPath.row == _detailCellIndexPath.row && _detailCellIndexPath) { NSLog(@"detailCell"); ItemDetailCell *detailCell = [tableView dequeueReusableCellWithIdentifier:DetailCellIdentifier forIndexPath:_detailCellIndexPath]; //customize cell return detailCell; } else { CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; //customize cell return cell; } 中尝试的方式:

NSLog(@"detailCell")

我确实在控制台中返回了{{1}},所以我知道它已被调用,但它仍然没有调整单元格高度。

非常感谢任何帮助!提前谢谢。

1 个答案:

答案 0 :(得分:1)

之后也会调用

heightForRowAtIndexPath

[self.tableView beginUpdates];
[self.tableView endUpdates];

您是否有任何理由不想将单元格添加到后备集合中?最简单的解决方案是将特定项添加到表视图支持数组中,然后在insertRowAtIndexPath beginUpdates块内调用endUpdates。这将触发标准的委托/数据源表视图方法(包括heightForRowAtIndexPath),因此您可以根据具体的UITableViewCell类(ItemDetailCellCustomCell)返回不同的大小。

相关问题