单选功能
首先我们
_tableView.allowsMultipleSelectionDuringEditing = YES;
[_tableView setEditing:YES animated:YES];
然后在 didSelectRowAtIndexPath 选中数据 数据添加到数组中
NSIndexPath *lastIndex = [NSIndexPath indexPathForRow:_index inSection:0];
UITableViewCell *lastCell = [tableView cellForRowAtIndexPath:lastIndex];
lastCell.selected = YES;
_index = indexPath.row;
//afterDelay为延迟多少删除上次的选中效果
[_tableView performSelector:@selector(deselectRowAtIndexPath:animated:) withObject:lastIndex afterDelay:.0];
在 didDeselectRowAtIndexPath 从数组中移除数据
NSIndexPath *lastIndex = [NSIndexPath indexPathForRow:_index inSection:0];
UITableViewCell *lastCell = [tableView cellForRowAtIndexPath:lastIndex];
lastCell.selected = NO;
_index = -1;
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;
}
多选
多选相对简单点 直接使用就行