动画行删除后重新加载表 [英] reloadTable after animated row deletion

查看:102
本文介绍了动画行删除后重新加载表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表格视图,其中包含可以删除的单元格。删除单元格时,我想显示删除动画,例如 UITableViewRowAnimationFade 。问题是我的表视图的单元格具有交替的背景颜色,因此在动画完成后我需要 -reloadData 来修复已删除单元格下面的所有单元格的颜色。

I have a table view with cells that can be deleted. When a cell is deleted, I would like to display a deletion animation such as UITableViewRowAnimationFade. The problem is that my table view's cells have alternating background colors, so I need to -reloadData after the animation completes to fix the colors of all cells below the deleted cell.

所以,如果你还没读过这篇文章,我需要一种在表视图动画完成后运行一些代码的方法。我目前正在使用 performSelector:withObject:afterDelay:并硬编码动画延迟的近似值。这种方法有效,但必须有更好的方法:

So, incase you haven't read this far, I need a way to run some code after a table view animation is complete. I am currently using performSelector:withObject:afterDelay: and hardcoding an approximation of the animation delay. This method works, but there must be a better way to do it:

NSIndexPath * path = [listTable indexPathForCell:deletingCell];
NSArray * indexPaths = [NSArray arrayWithObject:path];
[listTable deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade];
[listTable performSelector:@selector(reloadData) withObject:nil afterDelay:0.35];

在这种情况下,我假设 UITableViewRowAnimationFade 完成时间不到0.35秒。

In this case I am assuming that UITableViewRowAnimationFade will take less than 0.35 seconds to complete.

推荐答案

你也可以使用相同延迟的NSTimer(尽管不需要,-performSelector: withObject:afterDelay:工作正常。)

You could also use NSTimer with the same delay (although unneeded, -performSelector:withObject:afterDelay: works fine).

另一种选择是在 deletionCell 之后循环遍历单元格( path )并重绘它们,或者将索引路径添加到数组并调用 reloadRowsAtIndexPaths:withRowAnimation:,如下所示。然后你也可以使用 UITableViewRowAnimationFade

Another option would be to loop through the cells after deletingCell (path) and redraw them, or add the index paths to an array and call reloadRowsAtIndexPaths:withRowAnimation: as shown below. Then you could also use the UITableViewRowAnimationFade

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

这篇关于动画行删除后重新加载表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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