我使用2個多行標籤製作自定義單元格並將此標籤固定到所有面。當在-tableView:heightForRowAtIndexPath:
爲iOS> = 8我返回UITableViewAutomaticDimension
。但是當表格視圖出現時,單元格高度比應該大。在向下滾動之後,向上滾動單元格取正常高度。如何解決這個問題?與UITableViewAutomaticDimension錯誤的UITableViewCell高度
代碼高度:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8) {
return UITableViewAutomaticDimension;
}
static CCTopicTableViewCell *cell;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
cell = [tableView dequeueReusableCellWithIdentifier:@"topicCellIdentifier"];
});
cell.topic = [self.topics topicAtIndexPath:indexPath];
cell.bounds = CGRectMake(0, 0, CGRectGetWidth(self.tableView.bounds), CGRectGetHeight(cell.bounds));
[cell setNeedsLayout];
[cell layoutIfNeeded];
CGSize size = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
return size.height + 1;
}
而結果:
滾動後:
謝謝,這解決了我的問題。不知道我明白它爲什麼修復它,但我確信在對該主題進行更多研究之後,它會找到我。再次感謝! – 2015-03-27 18:40:20
任何想法_why_這是否有效? – 2017-12-15 21:13:03