【发布时间】:2015-02-07 14:21:17
【问题描述】:
我制作了带有 2 个多行标签的自定义单元格,并将这些标签固定到所有侧面。在 iOS >= 8 的 -tableView:heightForRowAtIndexPath: 中,我返回 UITableViewAutomaticDimension。但是当表格视图出现时,单元格高度大于应有的高度。在我向下滚动然后向上滚动后,单元格采用正常高度。如何解决此问题?
高度代码:
- (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;
}
结果:
滚动后:
【问题讨论】:
标签: ios uitableview autolayout