在UITableViewCell中进入编辑模式时隐藏UITableViewCells(类似于Contacts应用程序)

时间:2011-09-25 11:56:06

标签: ios uitableview contacts hidden

有人知道在进入编辑模式时如何从分组的UITableView中隐藏多个单元格?我希望在离开编辑模式时,在“联系人”应用程序中看到行以隐藏动画效果。

如您所知,在联系人编辑模式下,行数比切换回正常模式时多。我想知道如何顺利​​完成切换。

请注意,我的UITableView子类使用IBOutlets从同一个nib加载静态UITableViewCell。

2 个答案:

答案 0 :(得分:4)

只是删除或插入多组行的人的更新:

[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths: ......];
[self.tableView insertRowsAtIndexPaths: ......];
[self.tableView removeRowsAtIndexPaths: ......];
[self.tableView endUpdates];

:d

答案 1 :(得分:2)

设置UITableView的编辑模式时,必须先更新数据源,然后插入/删除行。

- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
    [super setEditing:editing animated:animated];
    [tableView setEditing:editing animated:animated];

    // populate this array with the NSIndexPath's of the rows you want to add/remove
    NSMutableArray *indexPaths = [NSMutableArray new];

    if(editing) [self.tableView deleteRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationFade];
    else [self.tableView insertRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationFade];

    [indexPaths release];
}