滑动删除

// 实现滑动删除

// 什么时候调用

- (void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath

{

 

    // 创建 indexpath

    //    NSIndexPath* index = [NSIndexPath indexPathForRow:2 inSection:0];

 

    [self.contacts removeObjectAtIndex:indexPath.row];

    //    [self.contacts removeObjectAtIndex:index.row];

 

    NSLog(@"%@", indexPath);

 

    // 删除模型

    //    [self.contacts removeObject:self.contacts[indexPath.row]];

 

    // 1.reload data

    //    [self.tableView reloadData];

    // 2.删除一行

 

    // 执行的前提条件: 先删除模型

    // self.tableview 里面有个数组专门来记录 当前cell有多少个.

    // 判断和你的模型数组 是不是数量一致

    // 如果和模型数组不一致 直接报错

    [self.tableView deleteRowsAtIndexPaths:@[ indexPath ] withRowAnimation:UITableViewRowAnimationLeft];

 

    //    for (int i = 0; i < self.contacts.count; i++) {

    //        NSLog(@"%@",[self.contacts[i] name]);

    //    }

 

    [NSKeyedArchiver archiveRootObject:self.contacts toFile:kContactsFilePath];

}

 

// 改变滑动删除出来的文字

- (NSString*)tableView:(UITableView*)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath*)indexPath

{

    return @"删除";

}

原文地址:https://www.cnblogs.com/gzz2016/p/5669945.html