【发布时间】:2017-07-14 08:18:20
【问题描述】:
我有一个 tableView,在每个 UITableViewCell(称为此 parentCell)中,我有另一个包含单元格的 tableView(称为此 childCell)。我正在使用 UITableViewAutomaticDimension 来动态调整两个单元格的高度。我可以通过这种方式成功调整 childCell 的高度,但是,我无法将 UITableViewAutomaticDimension 应用于 parentCell,因为在调用 heightForRow 时,childCell 的高度尚未估计。
是否可以使用 UITableViewAutomaticDimension 来估计父单元格的高度,这将是所有 childCell 的高度相加的高度?还是我必须手动执行此操作?
//in ViewDidLoad
parentTableView.rowHeight = UITableViewAutomaticDimension
//in ParentCell's tableView's cell for row
cell.childTableView.rowHeight = UITableViewAutomaticDimension
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
【问题讨论】: