Is it possible to disable floating headers in UITableView with UITableViewStylePlain?

前端 未结 29 1107
走了就别回头了
走了就别回头了 2020-11-29 15:02

I\'m using a UITableView to layout content \'pages\'. I\'m using the headers of the table view to layout certain images etc. and I\'d prefer it if they didn\'t

29条回答
  •  甜味超标
    2020-11-29 15:33

    The snippet display a sticky header only for the first section. Others section headers will float with a cells.

    func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
    
        if section == 1 {
            tableView.contentInset = .zero
        }
    
    }
    
    func tableView(_ tableView: UITableView, didEndDisplayingHeaderView view: UIView, forSection section: Int) {
        if section == 0 {
            tableView.contentInset = .init(top: -tableView.sectionHeaderHeight, left: 0, bottom: 0, right: 0)
        }
    }
    

提交回复
热议问题