【发布时间】:2017-06-30 05:15:24
【问题描述】:
我有一个UITableViewCell,它在顶部包含一个UICollectionView,在底部包含一个UITableView。这个想法是在内部UITableView 中创建动态数量的单元格,并且包含两个子视图的父UITableViewCell 将按比例增加其高度。
我正在尝试利用UITableViewCell 的estimatedRowHeight + UITableViewAutomaticDimention 功能,这将允许单元格高度动态增加。但是,它不起作用。它从视图中完全删除了嵌入的UITableView。
我没有限制封闭的UITableView 的高度,所以我不确定它为什么不起作用。
这是尝试制作动态大小的UITableViewCell 的实现:
class OverviewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.title = "Enclosed Table View Example"
}
func numberOfSections(in tableView: UITableView) -> Int {
return 3
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return 325 // Height for inner table view with 1 cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 45
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let cell = tableView.dequeueReusableCell(withIdentifier: "appHeaderCell") as! AppHeaderCell
return cell
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "appCell", for: indexPath) as! AppCell
return cell
}
}
我唯一的猜测是约束bottom = Inner Table View.bottom + 7 导致了这个问题,但是当这个约束被移除时,整个视图就会崩溃。
如何使复杂的外部UITableViewCell根据嵌入的UITableView中的单元格数量动态调整高度?
【问题讨论】:
标签: ios swift uitableview autolayout constraints