UITableView header view overlap cells in iOS 10

The bug was in the fact that the view was being resized automatically, so its frame height really was 0 when it was being attached to the tableView, which explains the behavior.

Setting the autoresizingMask to none fixed this bug.

_headerView.autoresizingMask = UIViewAutoresizingNone

Again, it wasn't necessary in iOS 9 and below. Hope this helps someone else.


Here is a more Swift approach

tableView.tableHeaderView?.translatesAutoresizingMaskIntoConstraints = false

Or you can do it directly in your header

 myHeaderView.translatesAutoresizingMaskIntoConstraints = false

Also you must call these two delegate methods.

  func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        return yourHeaderView
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 30 // Your preferred height
    }