Search code examples
swiftuitableviewuikit

Why does "tableHeaderView" of UITableView scroll up with a content?


How can I make it stay fixed? Its behavior is so counterintuitive!
My tableView has a .plain style, and I don't have any sections. It's a very simple table with many rows (so they scroll). However, I need the tableHeaderView to remain fixed while scrolling the content. I've tried everything, but nothing works — it always moves.
According to the info I found, .plain style tableView header actually should stay fixed. But in practice it's just not the case. Very confusing.


Solution

  • You are confusing two different things. A section header stays fixed (it is pinned to the top, as long as you are "in" that section). A table header view scrolls up with the table rows.

    So, if you have only one section, use a section header here. Or, just put another view above the table view.