关于tableview 编辑下多选择处理

33 篇文章 0 订阅


1.设置可以多选择(并且设置tintColor 可以改变右侧 符号颜色)

  self.tableView.allowsMultipleSelectionDuringEditing = YES;

  self.tableView.tintColor = MAIN_THEME_GREEN_COLOR;


效果图:



2.定义下面修改状态的toolView

  

    UIView *spliter = [UIView new];

    spliter.backgroundColor = NORMAL_SPLITER_GREY;

    [self.toolView addSubview:spliter];

    [spliter mas_makeConstraints:^(MASConstraintMaker *make) {

        make.width.mas_equalTo(self.toolView);

        make.height.mas_equalTo(0.5);

        make.left.mas_equalTo(0);

        make.top.mas_equalTo(0);

    }];

    

    

    self.changeSignBtn = [UIButton new];

    self.changeSignBtn.titleLabel.font = BIG_FONT;

    [self.changeSignBtn setTitle:@"签到" forState:UIControlStateNormal];

    [self.changeSignBtn setTitleColor:MAIN_THEME_GREEN_COLOR forState:UIControlStateNormal];

    [self.changeSignBtn addTarget:self action:@selector(batchChange:) forControlEvents:UIControlEventTouchUpInside];

    [self.toolView addSubview:self.changeSignBtn];

.....

    

    self.changeLateBtn = [UIButton new];

    self.changeLateBtn.titleLabel.font = BIG_FONT;

    [self.changeLateBtn setTitle:@"迟到" forState:UIControlStateNormal];

    [self.changeLateBtn setTitleColor:MAIN_THEME_GREEN_COLOR forState:UIControlStateNormal];

    [self.changeLateBtn addTarget:self action:@selector(batchChange:) forControlEvents:UIControlEventTouchUpInside];

    [self.toolView addSubview:self.changeLateBtn];

.....

    

    self.changeEarlyBtn = [UIButton new];

    self.changeEarlyBtn.titleLabel.font = BIG_FONT;

    [self.changeEarlyBtn setTitle:@"早退" forState:UIControlStateNormal];

    [self.changeEarlyBtn setTitleColor:MAIN_THEME_GREEN_COLOR forState:UIControlStateNormal];

    [self.changeEarlyBtn addTarget:self action:@selector(batchChange:) forControlEvents:UIControlEventTouchUpInside];

    [self.toolView addSubview:self.changeEarlyBtn];

.....

    

    

    self.changeUnsignBtn = [UIButton new];

    self.changeUnsignBtn.titleLabel.font = BIG_FONT;

    [self.changeUnsignBtn setTitle:@"未签到" forState:UIControlStateNormal];

    [self.changeUnsignBtn setTitleColor:MAIN_THEME_GREEN_COLOR forState:UIControlStateNormal];

......



3.右键编辑状态事件并且给toolview添加动画

-(void)showToolBar:(id)sender{

    if (self.tableView.isEditing) {

        [self.navigationItem.rightBarButtonItem setTitle:@"编辑"];

        [self.tableView setEditing:NO animated:YES];

        

        [UIView beginAnimations:nil context:nil];

        [UIView setAnimationDuration:0.3];

        [self.toolView mas_updateConstraints:^(MASConstraintMaker *make) {

            make.top.mas_equalTo(self.view.mas_bottom);

        }];

        [self.view layoutIfNeeded];

        [UIView commitAnimations];

        

        self.selectedStatisticArray = [NSMutableArray<TchStdSignDetail*> new];

        

    }else{

        [self.navigationItem.rightBarButtonItem setTitle:@"完成"];

        [self.tableView setEditing:YES animated:YES];

        

        [UIView beginAnimations:nil context:nil];

        [UIView setAnimationDuration:0.3];

        [self.toolView mas_updateConstraints:^(MASConstraintMaker *make) {

            make.top.mas_equalTo(self.view.mas_bottom).offset(-40);

        }];

        [self.view layoutIfNeeded];

        [UIView commitAnimations];

        

        self.selectedStatisticArray = [NSMutableArray<TchStdSignDetail*> new];

    }

}


4.勾选添加删除的逻辑

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

if (tableView.editing) {

      .......省略.......(statistic 是Model数据)

        if([self.selectedStatisticArray containsObject:statistic]){

            [self.selectedStatisticArray removeObject:statistic];

        }else{

            [self.selectedStatisticArray addObject:statistic];

        }

    }else{

        [tableView deselectRowAtIndexPath:indexPath animated:NO];

    }


}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值