动态表视图高度

时间:2019-04-14 18:12:42

标签: ios uitableview swift5 custom-sections

我在UITableView上实现了可扩展部分,现在我的问题是,当UIViewController加载表时,该部分下面有行。

未展开:

enter image description here

展开:

enter image description here

如果该部分未展开,我希望UITableView没有行,因此我可以在该部分下方设置另一个UIView。展开该部分后,UIView应该消失,表格视图将显示在整个屏幕上。

2 个答案:

答案 0 :(得分:1)

只需实现viewForFooterInSection并返回一个空视图。

func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
    return UIView(frame: .zero)
}

答案 1 :(得分:1)

func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
    return UIView()
}

只需使用此代码,它将删除您不需要的行。