gpt4 book ai didi

ios - 错误的 UITableViewCell 高度与 UITableViewAutomaticDimension

转载 作者:可可西里 更新时间:2023-11-01 03:37:46 25 4
gpt4 key购买 nike

我制作了带有 2 个多行标签的自定义单元格,并将这些标签固定在所有边上。当在 -tableView:heightForRowAtIndexPath: for iOS >= 8 时,我返回 UITableViewAutomaticDimension。但是当表格 View 出现时,单元格高度比应有的要大。在我向下滚动然后向上滚动后,单元格采用正常高度。如何解决此问题?

高度代码:

   - (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 的 estimatedRowHeight 并且每次设置多行标签的文本时更新 preferredMaxLayoutWidth 时,问题就消失了

关于ios - 错误的 UITableViewCell 高度与 UITableViewAutomaticDimension,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28383220/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com