Hiding UITableViewCells when entering edit mode in UITableViewCell (similar to Contacts app)

夙愿已清 提交于 2020-01-01 16:42:09

问题


Does anyone know how to hide a number of cells from the grouped UITableView when entering in edit mode? I would like the rows to hide with animation effect as seen in the Contacts app when going out of editing mode.

As you know, when in Contacts editing mode, there are more rows than when switching back to normal mode. I would like to know how the switching is done smoothly.

Note that my UITableView subclass is loading static UITableViewCells from the same nib using IBOutlets.


回答1:


When you set the editing mode of the UITableView, you have to first update your data source and then insert/delete rows.

- (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];
}



回答2:


just an update for the ones who remove or insert more than one group of rows:

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

:D



来源:https://stackoverflow.com/questions/7545337/hiding-uitableviewcells-when-entering-edit-mode-in-uitableviewcell-similar-to-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!