gpt4 book ai didi

iOS UITableViewCell 自动调整大小错误

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

我有一个使用 .xib 设计的 UITableViewCell,它使用单元格自动调整大小。在 iOS 9 中运行良好,但在 iOS 8 中,单元格不会自行扩展,并且内部标签仍保留 1 行文本。如果单元格离开屏幕并返回(即滚动后),则所有标签均正常。

想法?我认为这是一个 iOS 8 错误。

enter image description here enter image description here

最佳答案

我遇到过同样的问题。如果您的约束设置正确,您需要在返回单元格之前为单元格中的每个 UILabel 设置 preferredMaxLayoutWidth。这是一些示例代码

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
cell.lblTitle.text = @"N";
cell.lblDetails.text = @"bla bla";
cell.lblOther.text = @"other text";


// Configure the cell...
CGfloat leftPading =// "your logo width + spacing between logo and label"
CGfloat rightPading = //your label trailing space
cell.lblTitle.preferredMaxLayoutWidth = CGRectGetWidth(tableView.bounds)-(leftPading +rightPading);
cell.lblDetails.preferredMaxLayoutWidth = CGRectGetWidth(tableView.bounds)-(leftPading +rightPading);
[cell setNeedsUpdateConstraints];
[cell updateConstraintsIfNeeded];

return cell;
}

Have a look at this to know how to put constrains properly

希望对您有所帮助。

关于iOS UITableViewCell 自动调整大小错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35267099/

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