使用其中的 tableView 动态调整单元格大小 (iOS)
Dynamically resizing cell with a tableView within it (iOS)
我有一个 tableView,在每个 UITableViewCell(称为此 parentCell)中,我有另一个包含单元格的 tableView(称为此 childCell)。我正在使用 UITableViewAutomaticDimension 动态调整两个单元格的高度。我可以通过这种方式成功地调整 childCell 的高度,但是,我无法将 UITableViewAutomaticDimension 应用于 parentCell,因为当调用 heightForRow 时,childCell 的高度尚未估计。
是否可以使用 UITableViewAutomaticDimension 来估计父单元格的高度,即所有子单元格的高度加在一起的高度?还是我必须手动执行此操作?
//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
}
执行此操作的唯一方法是使用部分而不是将表格视图放置在单元格中。
我有一个 tableView,在每个 UITableViewCell(称为此 parentCell)中,我有另一个包含单元格的 tableView(称为此 childCell)。我正在使用 UITableViewAutomaticDimension 动态调整两个单元格的高度。我可以通过这种方式成功地调整 childCell 的高度,但是,我无法将 UITableViewAutomaticDimension 应用于 parentCell,因为当调用 heightForRow 时,childCell 的高度尚未估计。
是否可以使用 UITableViewAutomaticDimension 来估计父单元格的高度,即所有子单元格的高度加在一起的高度?还是我必须手动执行此操作?
//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
}
执行此操作的唯一方法是使用部分而不是将表格视图放置在单元格中。