UITableView viewForHeaderInSection not called during reloadData
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
If tableView(_:viewForHeaderInSection:) is not called after reloadData(), that usually does not mean the table view is broken. UITableView creates header views on demand, reuses them, and may decide that a visible header does not need to be recreated just because the data source was reloaded.
The key point is that reloadData() refreshes the model and row structure, not the exact sequence of delegate calls you might expect. If you need a particular header to update immediately, target that section more explicitly.
Why the Delegate Method May Not Fire
UITableView asks for headers only when it needs them. Common reasons the method is not called include:
- the section is off-screen
- the header height is zero or effectively hidden
- the table already has a reusable header view it can keep using
- the section is using a title-based header rather than a custom view
This is similar to cell reuse. Logging inside viewForHeaderInSection can be misleading because a missing log line does not always mean the UI failed to update.
Make Sure the Header Is Actually Configured to Exist
A custom section header needs a visible height and a registered reuse identifier if you are using UITableViewHeaderFooterView.
If the header height is effectively zero, UIKit has no reason to ask for the view.
Use reloadSections When Only Headers Changed
If the section data did not fundamentally change but the header text or appearance did, reloadSections is often better than reloadData().
That tells the table view exactly which section needs to be reconsidered. It is more precise and usually easier to reason about than reloading everything.
Update the Visible Header Directly When Needed
If the header is already on screen, you can also update it directly.
This is useful when you want the currently visible header to change immediately without waiting for reuse or for the section to scroll off and back on.
reloadData() Does Not Promise Full View Recreation
This is the source of most confusion. reloadData() invalidates the table view's current data and causes it to ask the data source for what it needs to draw again. It does not promise that every existing row and section header will be thrown away and rebuilt from scratch in a predictable order.
That means reloadData() is a data refresh tool, not a delegate-call trigger.
If you changed header height constraints or auto layout conditions, beginUpdates() and endUpdates() can also help the table recalculate layout.
Common Pitfalls
A common mistake is expecting viewForHeaderInSection to be called for off-screen sections immediately after reloadData(). Another is returning zero height, which prevents the header from existing in the first place. Developers also sometimes call reloadData() for a tiny header-only change when reloadSections or direct header updates are a better fit. Finally, mixing titleForHeaderInSection and viewForHeaderInSection without being clear about which header style is active can make the behavior look inconsistent.
Summary
- '
reloadData()does not guarantee a fresh call toviewForHeaderInSectionfor every section.' - Header views are created on demand and reused.
- Make sure the section header has a visible height and proper registration.
- Use
reloadSectionswhen a specific header needs to refresh. - Update the visible header directly if you need an immediate on-screen change.
Related reading
- UITableView with fixed section headers
- UITableview with more than One Custom Cells with Swift
- UITableViewCell Separator disappearing in iOS7
- UITableViewCell, show delete button on swipe
- UITableViewCell show white background and cannot be modified on iOS7
- UITableViewCell subview disappears when cell is selected
- UITableViewCell with UITextView height in iOS 7?
- UITableViewHeaderFooterView Unable to change background color
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.