2011-05-07 58 views
1

我有一个小问题:的UITableViewController取消编辑模式的动画调用表reloadData]内(无效)setEditing时

我做了我setEditing方法:

- (void)setEditing:(BOOL)editing animated:(BOOL)animate { 
    [super setEditing:editing animated:animate]; 
    [mainTableView reloadData]; 
} 

我用reloadData调用:cellForRowAtIndexPath,然后,如果表处于编辑模式,我会改变我的单元格的外观(例如隐藏一些标签);

问题是,当我调用[mainTableView reloadData]编辑动画(红圈从左到右滑动,我的单元格向右滑动)不存在。如果不调用它,一切正常,但我无法自定义我的单元格,因为cellForRowAtIndexPath不会再次调用。

任何建议,使其工作?

谢谢!

回答

1

也许你会尝试与[的tableView beginUpdates][的tableView endUpdates]更新您的桌子吗?你需要重新加载所有的单元格还是只有一部分?

编辑:下面是重装的所有单元格的代码:

[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是存储您的cell.textLabel价值观或类似的东西NSArray的实例...

+0

其实我只需要更新可见单元格,因为未显示的单元格将在需要时调用cellForRowAtIndexPath。我试图在beginUpdates和endUpdates之间插入reloadData,但它没有奏效。任何其他的消化?谢谢 – PGstudio 2011-05-07 11:23:22

+0

它不这样工作。我用代码示例更新了我的答案。 – akashivskyy 2011-05-07 13:17:04

+0

嘿Kashiv,它与你的榜样运作良好。无论如何,动画是默认编辑单元格的吗?幻灯片的权利?我尝试过所有类型的动画,但没有一个看起来像是Slide来制作一个动画。谢谢 – PGstudio 2011-05-07 16:38:28

相关问题