首先,需要在.h文件中给tableview添加实现UITableViewDelegate和UITableViewDataSource
其次,在.m文件中添加实现函数:
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
//编辑的方式为从列表中删除记录
//如果你要删除的类型是NSMutableArray,可参照以下
[self.dataArray removeObjectAtIndex:indexPath.row];
[tableView reloadData]; // tell table to refresh now
}
}
参考链接:
http://stackoverflow.com/questions/9471642/swipe-to-delete-tableview-row