Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reload and animate just one UITableView cell/row?

how can I reload and animate just one cell/row ? Right now i download some files. Everytime a file finished downloading, i call it's finished delegate and call [tableview reload]. But then the whole table reloads. And how can i animate the table, so that it doesn't blink in. For example a fade effect or so.

greets Max

like image 589
madmax Avatar asked Mar 24 '11 11:03

madmax


People also ask

How can we use a reusable cell in UITableView?

For performance reasons, a table view's data source should generally reuse UITableViewCell objects when it assigns cells to rows in its tableView(_:cellForRowAt:) method. A table view maintains a queue or list of UITableViewCell objects that the data source has marked for reuse.


1 Answers

Use the following UITableView instance method:

- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation 

You have to specify an NSArray of NSIndexPaths that you want to reload. If you just want to reload. If you only want to reload one cell, then you can supply an NSArray that only holds one NSIndexPath. For example:

NSIndexPath* rowToReload = [NSIndexPath indexPathForRow:3 inSection:0]; NSArray* rowsToReload = [NSArray arrayWithObjects:rowToReload, nil]; [myUITableView reloadRowsAtIndexPaths:rowsToReload withRowAnimation:UITableViewRowAnimationNone]; 

You can see the UITableViewRowAnimation enum for all the possible ways of animating the row refresh. If you don't want any animation then you can use the value UITableViewRowAnimationNone, as in the example.

Reloading specific rows has a greater advantage than simply getting the animation effect that you'd like. You also get a huge performance boost because only the cells that you really need to be reloaded are have their data refreshed, repositioned and redrawn. Depending on the complexity of your cells, there can be quite an overhead each time you refresh a cell, so narrowing down the amount of refreshes you make is a necessary optimization that you should use wherever possible.

like image 68
James Bedford Avatar answered Nov 05 '22 19:11

James Bedford