【发布时间】:2017-10-16 18:07:58
【问题描述】:
我有一个有趣的场景。我有一些在单独的 xib 文件中设计的自定义 UITableViewCells。其中一个有一个 UIImageView,它会加载大小不恒定的图像,因此这意味着 UIImageView 的高度必须是灵活的。该单元格还有一个包含一些 UILabel 的 UIView,并且 UIView 的大小是恒定的,例如 100。我想在 didselectrowatindexpath 事件上展开和折叠单元格。要折叠单元格,我必须隐藏具有一些标签的 UIView。请在这方面指导我以实现目标。
我的问题也是“如何计算单元格展开和折叠时行的高度。”谢谢
编辑:这是我尝试过的。 . .但是失败了
- (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;
}
}
【问题讨论】:
-
给我们看一些代码。到目前为止,您尝试过什么?
标签: ios objective-c uitableview custom-cell