is there a way to get all the section header views that are visible?
something similar to UITableView\'s visibleCells instance method..
All of these answers turn out to be overly complicated. All you need to do is call headerView(forSection:)
in a loop. It will return nil for header views that are not visible.
However, there is a catch: Your header views have to inherit from UITableViewHeaderFooterView
for this to work (which they technically should anyway, but everything except this works even if they don't so you can easily miss this.)
Once you have your class inheriting correctly, you can just do this:
for section in 0 ..< tableView.numberOfSections {
guard let header = tableView.headerView(forSection: section) as? CustomHeaderView else { continue }
header.update(...)
}