2

I have implemented the code necessary to take advantage of reusable header views as described in the accepted answer here UITableViewHeaderFooterView in InterfaceBuilder

To summarize, I have a NIB who's class derives from UITableViewHeaderFooterView, I register the NIB in viewDidLoad "forHeaderFooterViewReuseIdentifier" and I dequeueReusableHeaderFooterViewWithIdentifier in the "viewForHeaderInSection" method. This all works, compiles, and runs.

The code closely parallels the typical use/re-use of UITableViewCells also being used in this screen. If I set a breakpoint on the dealloc methods for both (the table cells, and table header cells) I see the table cells get created, re-used, and rarely dealloc'ed.

The call to dequeueReusableHeaderFooterViewWithIdentifier returns a non-nil value and the result gets returned as the viewForHeaderInSection. However, the header cell dealloc method gets called (for each header cell) every time reloadData is called on the table. The table cells don't, so in other words the header cells aren't really being reused, if the cell behavior is the standard for defining "re-use". Or, at least it can be said that the header cells aren't re-used as much as the cells are.

Apple provides an example of header reuse in the "Table View Animations and Gestures" code example. If I add a dealloc method to their custom header class, it DOES get called when table reloadData is called. (I added a timer to their class that calls reloadData every 10 seconds)

Does anyone know if this is the expected behavior and I'm misunderstanding "reuse", or has Apple not really implemented the reuse behavior for header cells that is seen in table cells?

Thanks

Community
  • 1
  • 1
software evolved
  • 4,314
  • 35
  • 45
  • I always thought that a reloadData would clean everything even cells, so for me the weird thing is that is not happening. The reuse behavior is intended for scrolling or batch updates, have you tried to insert cells or sections? I'm pretty sure that they would be reused. The reuse mechanism was made to increase performance while scrolling I can't see a point to do that while reloading. – Andrea May 07 '15 at 19:08
  • Andrea, I'm not concerned with either of the cases you have mentioned. – software evolved May 07 '15 at 21:01

0 Answers0