I have a multi-section UITableView with custom header views that need to know their section index. I currently record the section number in the tag field of UIView when creating the custom view in viewForHeaderInSection. However, when a row is deleted, the UITableView does not reload the section header views for header views visible on the screen, so their tag fields become out of sync. Calling reloadData on the table re-syncs the tag fields by recreating the header views, but calling reloadData interferes with the row deletion animation. Setting up a timer to call reloadData after a "short" period of time seems hacky and somewhat risky if the user ends up interacting with an out-of-sync header before the timer fires (I suppose I could add a state variable to prevent this, ugh).
I could I suppose keep track of all header views created in a container, and adjust their tags when rows are deleted (ugh again). But then how do I avoid leaking the Views? How do I know when the UITableView has released the view so I can delete my reference to them so they can be released?
This seems like way more work than it should be....am I missing something? I've noticed others have very similar issues and never seen a definitive approach to solving it.