How can we hide the tableHeaderView and tableFooterView?

前端 未结 8 534
我在风中等你
我在风中等你 2020-12-08 10:32

I have two buttons which i add it in one in table-footer and other one in table-header,i know how to hide the headerview of the table using this codetable.tableHeader

8条回答
  •  星月不相逢
    2020-12-08 10:49

    Try:

    tableView.tableHeaderView?.removeFromSuperview()
    tableView.tableHeaderView = UIView(frame: CGRect(x: 0, y: 0, width: 0, height: CGFloat.leastNonzeroMagnitude))
    tableView.layoutIfNeeded()
    

    Set an UIView with height as CGFloat.leastNonzeroMagnitude instead of '0'. This will remove the blank space appearing at the top after removing the tableViewHeader. This worked for me.

提交回复
热议问题