我有一个带有多个 UITableViewCell 的 UITableView(又名 ParentTableView)。每个 UITableViewCell 都包含一些标签和一个 UITableView(也称为 ChildTableView)。
ChildTableView 的行有不同数量的 UITableViewCell。
有两件事我需要帮助才能弄清楚。
1。 ChildTableView 的高度应该是其内容的高度。所以这个tableview上不应该有滚动条。它基本上只是一个列表。
2。将 ParentTableView 的行高设置为:(默认高度 + ChildTableView 根据问题 1 计算的高度)
最佳答案
在 tableView 完成加载单元格(获取其内容)后,使用内容大小更新 TableView 的框架。
所以在 reloadData
之后:
var bounds = tableView.bounds
bounds.size.height = tableView.contentSize.height
// You can add anything to the height now with bounds.size.height += something
tableView.bounds = bounds
您还可以使用 scrollEnabled = false
显式禁用滚动
关于ios - 根据子 UITableView contentSize Swift 动态设置 UITableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35869403/