gpt4 book ai didi

ios - 不自动布局的自调整 UITableViewCell 大小

转载 作者:行者123 更新时间:2023-11-30 11:37:22 25 4
gpt4 key购买 nike

我正在尝试创建一个自动调整大小的UITableView,但不想使用自动布局来布局它的 subview 。

有什么办法可以做到这一点吗?我正在设置

tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 40

但是在 layoutSubviews 中调整 self.frame.size.height 没有帮助,单元格保持在 40 高度,所以我假设我需要返回真实高度以不同的方法。对于UICollectionViewCells,方法是

override func preferredLayoutAttributesFitting(_ layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes

但我找不到 UITableViewCell 的等效项。

感谢您的指点。

最佳答案

实际上,当您将此 UITableViewAutomaticDimension 传递给 tableView 的 rowHeight 时,您无法创建没有自动布局的动态高度 tableViewCell

1- 返回 heightForCellAtRow 中指定的高度(如果已实现)

2- 从 Xib 返回正确的高度,或者如果您在代码中创建了约束

3-如果无效,将返回 40(默认)

关于ios - 不自动布局的自调整 UITableViewCell 大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49601332/

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