如何仅重新加载一个 UITableView 单元格/行并为其设置动画? [英] How to reload and animate just one UITableView cell/row?

查看:26
本文介绍了如何仅重新加载一个 UITableView 单元格/行并为其设置动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何仅重新加载一个单元格/行并为其设置动画?现在我下载了一些文件.每次文件下载完成时,我将其称为完成委托并调用 [tableview reload].但随后整个表重新加载.以及如何为表格设置动画,使其不会闪烁.例如淡入淡出效果等.

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 实例方法:

Use the following UITableView instance method:

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

您必须指定要重新加载的 NSIndexPathsNSArray.如果你只是想重新加载.如果您只想重新加载一个单元格,那么您可以提供一个仅包含一个 NSIndexPathNSArray.例如:

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.

这篇关于如何仅重新加载一个 UITableView 单元格/行并为其设置动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆