Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does a manually reused UITableViewCell disappear on row-reload?

If I keep a fixed UITableViewCell with reuseidentifier=nil as an ivar and return this instance for a specific row, and then reload this row specifically using [tableView reloadRowsAtIndexPaths:withRowAnimation:], the row contents disappear (or sometimes flicker). When I scroll away and back, it becomes visible again. If I do [tableView reloadData] on the other hand, it will not disappear.

  • Why does it disappear, when I reload the row ?
  • Why doesn't it, when I reload the whole table ?

Here is a sample project: https://github.com/hannesoid/HOTableViewTests

I tested this on iOS 6. I know that manually reusing a UITableViewCell in such a way (with out reuseidentifier & dequeueing) is not typically recommended, but in some quite static scenarios it would simplify things.

like image 502
Hannes Avatar asked Nov 13 '22 16:11

Hannes


1 Answers

UITableView is optimized by Apple so that it uses a reasonably small amount of memory and yet still has good performance for when cells appear on the screen. When you do something non-standard like this, and circumvent the optimization, you throw the whole machine out of whack. Here's what I suggest. If you have one specific row that you're now holding as an instance variable, why not simply try giving it a unique name for its reuseIdentifier? Let the kit work it out.

like image 161
Mario Avatar answered Jan 04 '23 01:01

Mario