Reputation: 11637
I have a UITableView
that contain about 20 rows in the iPad's viewport. I have a interval timer that will call UITableView's
reloadData
regularly(post it to UI thread).
Now when I scroll through the UITableView
with medium speed (not so fast), that UITableView
will refresh with flickering effect.
I have to write a function to manually update the UITableViewCell
label by looping through all the items in the array (this array keep all the items that show on UITableView
). I will execute this function when timer is running instead of calling reloadData
(as I mentioned above). Then the flickering issue is gone.
I believe that reloadData should be better than looping through all the data because reloadData will only refresh the current showing Cells instead of all the rows, but I couldn't figure out why the flickering happens. Anyone know why?
One thing I have to mention is I did use the CellIdentifier
correctly to reuse the cell and only create the cell when the retrieved cell is null.
Moreover, I do not have this issue in iPhone and I believe that it is because iPhone has lesser row compare to iPad.
Anyone can give some explanation about this issue?
Upvotes: 1
Views: 1603
Reputation: 538
I had the same problem with flickering when using reloadData
. I solved it by using indexPathsForVisibleRows
and cellForRowAtIndexPath:
to only update the visible cells. Performance is good since I don't have to iterate over the whole data set, but only a limited number of visible cells.
Upvotes: 3
Reputation: 2170
reloadData
causes the tableview to recreate the visible cells on screen which can result in a flickering since the cells get destroyed. There are better ways to reload the tableview. Are you using Core Data? If so the NSFetchedResultsController and it's delegate are a great way to update a tableview since it listens to changes in the underlying datasource and only updates the appropriate cells.
Upvotes: 0