【发布时间】:2018-05-24 15:38:12
【问题描述】:
我有一个非常简单的UITableViewController,我想在UITableViewCells 的每个textLabel 上设置一个文本。
高度应通过自动布局计算。因此,在我的viewDidLoad 中将以下值设置为tableView 属性:
tableView.estimatedRowHeight = UITableViewAutomaticDimension
tableView.rowHeight = UITableViewAutomaticDimension
这是我的cellForRow 方法,我在其中初始化默认的UITableViewCell 并将文本设置为其标签。
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
cell.textLabel?.numberOfLines = 0
cell.textLabel?.text = "hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello"
return cell
}
我的问题是,单元格不会根据标签的大小增长。此问题仅出现在 iOS 10 上。在 iOS 11 上,一切都按原样布置。
请查看以下截图:
- iOS 10
- iOS 11
编辑:2018 年 5 月 24 日
只有textLabel,如果estimatedRowHeight 上有实际值,它将起作用。
但是有一个样式为.subtitle 的单元格,并将值设置为descriptionLabel,布局将不起作用。同样的问题:iOS 10 不工作。 iOS 11 有效(单元格根据两个标签调整大小)。
【问题讨论】:
标签: swift uitableview uikit