美文网首页
UITableView左划删除cell

UITableView左划删除cell

作者: 雷霸龙 | 来源:发表于2017-07-26 10:53 被阅读23次

左划删除分为三个步骤:
第一步:设置cell可编辑状态为删除状态

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellEditingStyleDelete;
}

第二步:设置滑动后显示的字为@“删除”

- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return @"删除";
}

第三步:删除

- (void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // 先删除数组中的数据,然后再执行下面的删除cell
        [self.tableView deleteRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationAutomatic];
        [self.tableView reloadData];                    
    }
}

相关文章

网友评论

      本文标题:UITableView左划删除cell

      本文链接:https://www.haomeiwen.com/subject/nfpnkxtx.html