Deleting rows in table view Checklist

来源:互联网 发布:google linux翻墙插件 编辑:程序博客网 时间:2024/05/18 09:13

    //enable swipe-to-delete- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{    [items removeObjectAtIndex:indexPath.row];        //delete the corresponding row from the table view    NSArray *indexPaths = [NSArray arrayWithObject:indexPath];    [tableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationAutomatic];}

When the commitEditingStyle method is present (it comes from the table view data source), the table view will automatically enable the swipe-to-delete.

All we have to do is remove the item from our data model and delete the corresponding row from our table view.

原创粉丝点击