异常记录tableCellBlock

Cell关联Block不可传值indexPath进行deleteRows操作,当传入index用此deleteRows会index没有更新但是数组却在变化所以会溢出,可使用reloadData更新,因为所有的index都会更新.————————>deleteRow使用的时候单次删除一行会进行多次删除的时候不应该使用index path操作,也是不能用cell绑定index属性。

ture:

  __weakCooperaterShowViewController *weakSelf=self;

    showCell.ocShow=^(NSString *num,NSIndexPath *index){

        

        SwitchOptionalModel *switchModel=weakSelf.variousChange[index.row];

        switchModel.num=num;

        if (num.integerValue<=0) {

         

            [weakSelf.variousChange removeObjectAtIndex:index.row];

            

            [weakSelf.cooperaterShowTable reloadData];

            

        }

        

    };

当然,为了动画效果,肯定不能简单reloadData,丑爆了。策略:
cell发通知:


- (IBAction)reduceAction:(id)sender {

    

    NSInteger num=_selectedNum.text.integerValue-1;

    

    _selectedNum.text=[NSString stringWithFormat:@"%ld",num];

  

    [[NSNotificationCenter defaultCenter]postNotificationName:@"CooperKeepShow" object:nil userInfo:@{@"index":_indexPath,@"num":@(num)}];

    

    

}



- (IBAction)addAction:(id)sender {

    

    NSInteger num=_selectedNum.text.integerValue+1;

    

    _selectedNum.text=[NSString stringWithFormat:@"%ld",num];

    

    [[NSNotificationCenter defaultCenter]postNotificationName:@"CooperKeepShow" object:nil userInfo:@{@"index":_indexPath,@"num":@(num)}];

    

}


控制器接:

    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keepShowCooperNomal:) name:@"CooperKeepShow" object:nil];



-(void)keepShowCooperNomal:(NSNotification *)noti{

    

    NSDictionary *infoDic=noti.userInfo;

    

    NSNumber *num=infoDic[@"num"];

    NSIndexPath *index=infoDic[@"index"];

//通过传过来的index拿到原始标记的indexPath,匹配传值进入model里面indexPath,就可以拿到即使删除了也能确定位置的modelrow的确切位置。

    for (NSInteger i=0; i<_variousChange.count; i++) {

        SwitchOptionalModel *model=_variousChange[i];

        if (model.indexInShow.row ==index.row) {

            model.num=[NSString stringWithFormat:@"%ld",num.integerValue];

            if (!num.integerValue) {

                [_cooperaterShowTable beginUpdates];

                [_variousChange removeObject:model];

                [_cooperaterShowTable deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:i inSection:0]] withRowAnimation:UITableViewRowAnimationRight];

                [_cooperaterShowTable endUpdates];

                if (!_variousChange.count) {

                    

                    if (self.cooperaterShowChange) {

                        

                        self.cooperaterShowChange(YES,_noShowPoint);

                    }

                    [UIView animateWithDuration:.3 animations:^{

                        self.view.alpha=0;

                    }];

                }

            }

            return;

        }

    }

    


}

管饱记录,一切为了动画!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值