Programmatically remove the header of UITableView and automatically resizes the content to fill in the removed area

前端 未结 4 1167
渐次进展
渐次进展 2020-12-17 10:32

I have added a UIButton in the header section of the UITableView via the interface builder and would like to remove the access to the button in cer

4条回答
  •  遥遥无期
    2020-12-17 10:51

    I created a boolean property called removeHeader and then when ever I want to remove my header I call:

    func removeSectionHeader() {
            removeHeader = true
            self.tableView.reloadData()
        }
    

    Then when my tableView reloads it will call this tableView delegate method:

    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
            if removeHeader {
                return 0.0
            } else {
                let height = self.tableView.sectionHeaderHeight
                return height
            }
        }
    

提交回复
热议问题