cell一键全选和一键全不选

//cell一键全选和一键全不选
-(void)allSelectClick:(UIButton *)button
{
    self.indexPaths = [[NSMutableArray alloc]init];
    if (self.isAllSelect) {
        for (NSInteger i = 0; i < self.dataSourceAry.count; i++) {
            NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
            Entity *entity = self.dataSourceAry[indexPath.row];
            [self.indexPaths addObject:entity];
            [self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
        }
        button.selected = YES;
        self.isAllSelect = NO;
    }else{
        
        for (NSInteger i = 0; i < self.dataSourceAry.count; i++) {
            NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
            Entity *entity = self.dataSourceAry[indexPath.row];
            [self.indexPaths removeObject:entity];
            [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
        }
        button.selected = NO;
        self.isAllSelect = YES;
    }
}
//删除按钮
-(void)deleteClick
{
//    [self.dataSourceAry removeObjectsInArray:self.indexPaths];
    for (Entity *entity in self.indexPaths) {
        [self.dataSourceAry removeObject:entity];
        [Dao.sharedInstance remove:entity];
    }
    [self.tableView reloadData];
    [self bottomDisAppear];
    if (self.dataSourceAry.count == 0) {
        self.navigationItem.rightBarButtonItem = nil;
    }
}
//消除cell选中
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
    Entity *entity = self.dataSourceAry[indexPath.row];
    if (tableView.editing) {
        //NSArray *indexPaths = [tableView indexPathsForSelectedRows];
        [self.indexPaths removeObject:entity];
        if (self.indexPaths.count < self.dataSourceAry.count) {
            UIButton *allSelectButton = (UIButton *)[self.view viewWithTag:AllSelectButonTag];
            allSelectButton.selected = NO;
            self.isAllSelect = YES;
        }
    }
}

//选中cell
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    Entity *entity = self.dataSourceAry[indexPath.row];

        //NSArray *indexPaths = [tableView indexPathsForSelectedRows];
        [self.indexPaths addObject:entity];
        if (self.indexPaths.count == self.dataSourceAry.count) {
            UIButton *allSelectButton = (UIButton *)[self.view viewWithTag:AllSelectButonTag];
            allSelectButton.selected = YES;
            self.isAllSelect = YES;
            [self allSelectClick:allSelectButton];
        }
}


转载于:https://my.oschina.net/u/2430056/blog/519899

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值