iOS 11 Floating TableView Header

Viewed 12491

Have an app going with multiple sections, a few rows per section when "expanded", none when "collapsed". Each section has a section header, was reusing them using a subclass of UITableViewHeaderFooterView etc. So far so good.

Then in iOS 11:

Screenshot describing the issue

I've used the visual debugger, and confirmed it's my section header floating. All the rows beneath the header are displaying correctly, the other headers show fine.

In an effort to restore sanity, I threw out all of the reuse logic for the header and just made them programatically. Same same. All work pre-iOS 11, still float in iOS 11. The section which floats seems to change each time, so there's that.

Any ideas?

4 Answers

If you want to make change like in ahmedre answer for entire app, You can set this properties in AppDelegate didFinishLaunchingWithOptions

UITableView.appearance().estimatedRowHeight = 0
UITableView.appearance().estimatedSectionHeaderHeight = 0
UITableView.appearance().estimatedSectionFooterHeight = 0

I don't know why in my case, @ahmedre answer is not working...

So my answer maybe help you if you set all estimated properties to 0 also not working:

func tableView(_ tableView: UITableView, estimatedHeightForHeaderInSection section: Int) -> CGFloat {
    return 0.1
}

func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    return 0.1
}
Related