我有一个有趣的场景。我有一些在单独的xib文件中设计的自定义UITableViewCells。其中之一有一个UIImageView,它将加载大小不恒定的图像,所以这意味着UIImageView的高度必须灵活。这个单元格还有一个包含UILabels的UIView,并且UIView的大小是不变的,比如100。我想展开并折叠didselectrowatindexpath
事件上的单元格。要折叠单元格,我必须隐藏有一些标签的UIView。请在这方面指导我达到目标。 另外我的问题是“如何计算细胞展开和折叠时行的高度。”谢谢如何计算自定义展开/折叠UITableViewCell的高度动态
编辑:这是我所尝试过的。 。 。但失败
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
static DynamicTableViewCell *cell = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
});
[self setUpCell:cell atIndexPath:indexPath];
CGFloat cellHeight = [self calculateHeightForConfiguredSizingCell:cell];
if(cellHeight >0) {
if(cell.isExpanded) {
return cellHeight;
}
else
{
return (cellHeight - detailViewHeight); // cell.detailView.frame.size.height = 100
}
}
else {
return cellHeight;
}
}
向我们展示一些代码。你试过什么了? – onnoweb