我有一个问题困扰了我一段时间。如何为另一个 tableview 单元格内的 tableview 设置自动高度?
所以我有 MainTableView,里面有 3 个单元格 (这个 tableview 有自动高度) 和 3rd 单元格我在里面有另一个 tableView (我们称它为 SecondaryTableView,它对其 superview 有约束)
事情是前 2 个单元格的自动高度。
对于 SecondaryTableView 的设置,我尝试执行相同的操作,但对于单元格,我选择了 xib 文件。
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
tableView.dataSource = self
tableView.delegate = self
tableView.estimatedRowHeight = 900
tableView.rowHeight = UITableView.automaticDimension
registerCells()
}
private func registerCells() {
tableView.register(UINib(nibName: "MainCategorySectionTableViewCell", bundle: nil), forCellReuseIdentifier: "MainCategorySectionTableViewCell")
tableView.register(UINib(nibName: "AdPerHomePageTableViewCell", bundle: nil), forCellReuseIdentifier: "AdPerHomePageTableViewCell")
}
我附上了一张它在模拟器中的外观图片。绿色是第一个单元格,橙色是第二个单元格(已注册)。我稍微滚动了前 2 个单元格以查看差异。
可能是单元格上没有数据?但是我贴了一些标签,看起来一样
最佳答案
您需要使用 UITableView 的 intrinsicContentSize
变量。
Create a subclass for child tableView and override intrinsicContentSize.
Dynamic row heights of a UITableView inside a UITableViewCell
关于ios - 如何在tableview Cell中设置tableView的自动高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57988755/