我用 2 个多行标签制作自定义单元格,并将该标签固定到所有侧面。当在-tableView:heightForRowAtIndexPath:
for iOS >= 8我回来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 8 设置 tableView 的预计行高并且每次设置多行标签的文本时更新preferredMaxLayoutWidth时,问题就消失了
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)