UITableViewController 在 (void)setEditing 中调用 [table reloadData] 时取消编辑模式动画 [英] UITableViewController canceling Edit mode animation when calling [table reloadData] inside (void)setEditing
问题描述
我遇到了一个小问题:
我制作了我的 setEditing 方法:
i made my setEditing method:
- (void)setEditing:(BOOL)editing animated:(BOOL)animate {
[super setEditing:editing animated:animate];
[mainTableView reloadData];
}
我正在使用 reloadData 调用:cellForRowAtIndexPath,然后,如果表格处于编辑模式,我将更改单元格的外观(例如隐藏一些标签);
i'm using the reloadData to call: cellForRowAtIndexPath, and then, if the table is in edit mode, i'll change the appearance of my cell (hiding some labels, for example);
问题是当我调用 [mainTableView reloadData] 时,编辑动画(红色圆圈从左向右滑动,我的单元格向右滑动)不存在.如果不调用它,一切正常,但我无法自定义我的单元格,因为不会再次调用 cellForRowAtIndexPath.
The problem is when i call [mainTableView reloadData] the Edit animation (the red circle slides from left to right and my cell slides to the right) doesn't exist. If don't call it, everything works ok, but i can't customize my cell, since cellForRowAtIndexPath is not called again.
有什么建议可以让它发挥作用吗??
Any suggestion to make it work ??
谢谢!
推荐答案
也许您会尝试使用 [tableView beginUpdates] 和 [tableView endUpdates] 来更新您的表格?您需要重新加载所有单元格还是仅加载其中一些单元格?
Maybe you will try to update your table with [tableView beginUpdates] and [tableView endUpdates]? Do you need to reload all the cells or only some of them?
这是重新加载所有单元格的代码:
Here's the code for reloading all the cells:
[tableView beginUpdates];
NSMutableArray *updatedPaths = [NSMutableArray array];
for (NSNumber *row in yourArray) {
NSIndexPath *updatedPath = [NSIndexPath indexPathForRow:[row intValue] inSection:0];
[updatedPaths addObject:updatedPath];
}
[tableView reloadRowsAtIndexPaths:updatedPaths withRowAnimation:UITableViewRowAnimationFade];
[tableView endUpdates];
yourArray
是 NSArray 实例,您可以在其中存储 cell.textLabel 值或类似内容...
yourArray
is NSArray instance where you store your cell.textLabel values or something like that...
这篇关于UITableViewController 在 (void)setEditing 中调用 [table reloadData] 时取消编辑模式动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!