UITableView 多选

来源:互联网 发布:工信部 大数据证书 编辑:程序博客网 时间:2024/06/05 11:06
效果就是 cell.contentView 右移,左侧留一空圆,点击选中,再点取消选中。

[_rootTable setEditing:YES animated:YES]; 进入多选,然后实现 delegate:

12345678910111213141516171819202122232425
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{  // 关键所在    return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;}- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{    if (tableView.editing) {        if (_dataArray && [_dataArray count]>indexPath.row) {            NSDictionary *dict = [_dataArray objectAtIndex:indexPath.row];            [_pickedArray addObject:dict];        }    }}- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{    if (tableView.editing) {        if (_dataArray && [_dataArray count]>indexPath.row) {            NSDictionary *dict = [_dataArray objectAtIndex:indexPath.row];            [_pickedArray removeObject:dict];        }    }}