具体实现效果如下:
//代码很简单,只要实现如下的三个tableDataSource的三个代理方法
#pragma mark-UITableViewDataSource
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewCellEditingStyleDelete;
}//此方法是cell的编辑样式
-(NSString*)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{
return @"删除";
}//修改delete按钮上的文字
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
if (editingStyle==UITableViewCellEditingStyleDelete) {
//移除数组中对应的数据
[_data removeObjectAtIndex:indexPath.row];
//tabelView中删除一个单元格视图
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight];
}