7

I use UITableView with static cells. If I use reloadData, than everything is OK.

If I try reloadRowsAtIndexPaths it hides row. Row appears if I drag tableView up-down(when cell is updated).

Shmidt
  • 16,436
  • 18
  • 88
  • 136

3 Answers3

11

If your table cells are static (i.e., you are using the same cell object to replace the one that's currently displayed), what you're seeing is an artifact of the transition animation.

Think of it this way. Lets say you set UITableViewAnimationOptionFade. When the cell is to be replaced, the cell it's to be replaced with (which in this case is the exact same object) has a fade-in animation added to it. Then, the cell that is being replaced (again, it's all the same object) has a fade-out animation added to it. At the end, the cell is actually there, but it's invisible because the fade-out animation has made that cell object invisible.

In a non-static tableview, one in which the replacement cell is a different object than the cell to be replaced, this isn't a problem, as the animations are added to two different objects.

leftspin
  • 2,468
  • 1
  • 25
  • 40
  • I don't know how the framework/recommended pattern can ensure that the cells would in fact be different. Is there not the possibility of `dequeueReusableCellWithIdentifier` returning the same reusable cell as the one being hidden? It seems to me Apple should just fix this bug. There's no reason it can't support both scenarios with a simple check to see if the new cell == the old cell. – devios1 Sep 03 '14 at 17:56
  • No way that I've found. File a radar I guess. – leftspin Sep 11 '14 at 18:29
  • Nice explanation. What would the solution be then? – Josh Jun 22 '15 at 08:25
  • @Josh don't use a static cell, and always dequeue them. – leftspin Jul 01 '15 at 20:50
  • @leftspin In my case, I implemented a ListView for a Settings configuration UI, so each row is totally different. That is why I use static cells. – Josh Jul 02 '15 at 10:24
9

I had the same problem, it seems to be a bug. I experimented some and the problem doesn't occur when I set the animation option to UITableViewRowAnimationNone. Some other interesting stuff happens when you set that option to UITableViewRowAnimationTop, too.

Rudolf Adamkovič
  • 31,030
  • 13
  • 103
  • 118
Scott Berrevoets
  • 16,921
  • 6
  • 59
  • 80
1

I solved this by removing animation

tableView.reloadRows(at: [yourIndexPath], with: UITableView.RowAnimation.none)

Hope this helps to anyone searching for this.

Ilya Shevyryaev
  • 756
  • 6
  • 8