我需要强制UITableView
根据数据源加载所有单元格,并在UI上显示之前得到UITableView
高度。我还有其他基于该高度的逻辑。我的行具有动态高度,单元格内的内容是自动覆盖的。这就是为什么我不能手动计算(或不知道如何)。在我的情况下,在显示UITableView
之前获得高度至关重要。
请告知。
答案 0 :(得分:0)
现在,要求是找到填充数据的单元格高度
这样,您可以在tableView
上显示之前找到单元格的高度是的,您可以使用以下代码执行此操作:
/****/
- (CGFloat)heightForBasicCellAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellIdentifier= @"IDENTIFIER";
static dispatch_once_t onceToken;
static UITableViewCell *cell = nil;
dispatch_once(&onceToken, ^{
cell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier];
});
/**SET ALL DATA AND VALUES ON CELL*/
CGFloat height = [self calculateHeightForConfiguredSizingCell:cell];
// NSLog(@"height at indexPath %ld --> %f",(long)indexPath.row, height);
return height;
}
- (CGFloat)calculateHeightForConfiguredSizingCell:(UITableViewCell *)sizingCell {
[sizingCell setNeedsLayout];
[sizingCell layoutIfNeeded];
CGSize size = [sizingCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
CGFloat height = size.height;
return height + 1.0f; // Add 1.0f for the cell separator height
}