The Hit List Diary #11.2 – Reloading table rows

After the previous instalment, Chris Brandow asked me on Twitter:

I'm sure you already considered this, but what about [tableView reloadRowsAtIndexPaths:]?

I have to admit I hadn’t fully considered it as such ;-)
But there are a couple of reasons:

In a lot of cases where this is a problem, we’re using static table views, set up in the storyboards editor. I never implement -tableView:cellForRowAtIndexPath: to populate the cells in question, so asking for a reload wouldn’t get the updated values in there directly. Possibly we could update the cell’s label, and then reload the row (I haven’t tried it), but that seems a rather odd approach.

Reloading rows — or indeed a whole table — comes with an annoying penalty: it loses the selection. A lot of these cells are being used to lead into another view as part of a navigation stack (much like the Settings app). It’s a nice courtesy if the cell is still selected when it comes back into view, before then deselecting in an animated fashion. So you wind up having to save and then restore the selection after performing the reload.

Arguably then I’ve got two approaches, both with their own set of annoyances and pitfalls to be aware of. I guess just pick your own, and I might as well leave mine be!

© Mike Abdullah 2007-2015