我有一个带有 UILabel 的 UITableViewCell,它可以根据文本长度正确调整其高度。为此,我已正确设置 AutoLayout 约束并指定
tableView.rowHeight = UITableViewAutomaticDimension
我遇到的问题是,在单元格本身中按下 UIButton - 阅读更多后,UILabel 的测试变得更长。我以编程方式向 UILabel 添加文本,我希望单元格高度增加。我已经添加:
self.layoutIfNeeded()
self.updateConstraints()
在单元格中,但它不起作用。单元格保持相同的高度。
我还强制重新加载委托(delegate) UIViewController 中的单元格行 但它也不起作用。我在这里缺少一些基本的东西吗?
编辑:该问题与其他类似问题不同,因为我希望答案避免手动计算高度。由于 AutoLayout 完全能够在第一次加载时计算出正确的动态高度,我想应该有一种方法可以让它在标签中的文本变长时重新绘制单元格,而无需执行手动计算来估计行高。强>
最佳答案
Get the Label height dynamically and set the tableviewcell height
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Calculate the Label height and add it to default height of the cell
}
关于ios - 使用动态高度更改 UITableViewCell 中的 UILabel 文本长度不会正确调整其大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38587913/