使用tableView动态调整单元格大小(iOS)

时间:2017-07-13 19:55:42

标签: ios dynamic resize

我有一个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
}

1 个答案:

答案 0 :(得分:0)

执行此操作的唯一方法是使用部分而不是在单元格中放置tableview。

相关问题