我有一個有趣的場景。我有一些在單獨的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