如何重新加载和动画只是一个UITableView的单元格/行?

问题描述:

我怎么可以重新加载和动画只是一个单元格/行?
现在我下载了一些文件。每当一个文件下载完成后,我把它称为是完成委托,并调用[重装的tableview。
但随后整个表重载。我怎么能动画表,所以它不眨眼。例如淡入淡出效果左右。

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.

迎接最大

使用以下的UITableView 实例方法:

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

您必须指定一个的NSArray NSIndexPaths ,你要重新加载。如果你只是想重装。如果你只是想重装一个单元格,那么你可以提供一个的NSArray 只保存一个 NSIndexPath 。例如:

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];

您可以看到 UITableViewRowAnimation 枚举的动画行刷新所有可能的方式。如果你不希望任何动画,那么你可以使用该值 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.