UITableView reusable cells problem
I have a UITableView and its data gets refreshed from a server connection. For the UITableViewcell, I have layout some labels across the row. So it can consider as a grid with UILabels(total no of labels = table rows * table columns).
When the data gets refreshed I have added an animation for the UILabel to highlight the table cell update.(Labels background color changes for about 0.5 seconds and restore to the previous background color). There I compare the old value with new value and I 开发者_运维技巧added the animation with comparing those. It works fine.
My problem is when I scroll the table, because of the reusable cells the labels are getting animated.(although the corresponding values are not change). Anyone have an idea to how to avoid this issue? thanks.
It sounds like you're calling reloadData
and animating in tableView:cellForRowAtIndexPath:
. Don't do this. There's no guarantee that UITableView will reuse the same cell (it sounds like it does, but it's unwise to rely on this, and I'm pretty sure it doesn't for reloadRowsAtIndexPath:withRowAnimation:
). It will do the wrong thing if you remove a row, for example.
You can use -[UITableView visibleCells]
to get an array of the currently visible cells. Loop over the array and use a custom method to tell each cell to reload with animation.
精彩评论