購物車全選、單選相關(guān)處理

最近由于換工作,好長時(shí)間沒發(fā)表文章了,趁今晚閑來,發(fā)表一下,購物車處理相關(guān)的Demo

1.gif

單選、全選處理

//全選
- (IBAction)clikeMainSleocted:(UIButton *)sender {
    
    allprice = 0;
     __weak typeof(self) weakSelf = self;
    
    [self.data enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        WineModel *mod = obj;
        mod.seleoctedShop = !sender.selected;

        
        if(mod.seleoctedShop == NO){
            
            self.moneyMain.text = @"0";
        }else{
            
            int  total = mod.money.intValue * mod.shopCount;
            allprice = allprice + total;
            weakSelf.moneyMain.text = [NSString stringWithFormat:@"%d",allprice];
            
        }
        
         
    }];
    
    [self.table reloadData];

    sender.selected = ! sender.selected;
}
//選中
- (void)TableViewCellWithClikeSeleocCell:(TableViewCell *)cell{
    
    if(cell.mod.seleoctedShop){
        
        int total =  self.moneyMain.text.intValue + cell.mod.money.intValue * cell.mod.shopCount;
        self.moneyMain.text = [NSString stringWithFormat:@"%d",total];
        
    }else{
        
        int total =  self.moneyMain.text.intValue -   cell.mod.money.intValue * cell.mod.shopCount;
        self.moneyMain.text = [NSString stringWithFormat:@"%d",total];

    }
    
    
    if(self.shopCar.count == self.data.count){
        
        self.seleocMain.selected = YES;
    }else{
        self.seleocMain.selected = NO;
    }
    
}

加、減處理

//加
- (void)TableViewCellWithClikeAddCell:(TableViewCell *)cell{
    
    int main = self.moneyMain.text.intValue + cell.mod.money.intValue;
    self.moneyMain.text = [NSString stringWithFormat:@"%d",main];
    if(![self.shopCar containsObject:cell.mod]){
        
        [self.shopCar addObject:cell.mod];
    }
    
}
//減
- (void)TableViewCellWithClikeDeleocCell:(TableViewCell *)cell{
    
    int main = self.moneyMain.text.intValue - cell.mod.money.intValue;
    self.moneyMain.text = [NSString stringWithFormat:@"%d",main];
    if(cell.mod.shopCount == 0){
        
        [self.shopCar removeObject:cell.mod];
    }
}

購物車處理Demo

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 發(fā)現(xiàn) 關(guān)注 消息 iOS 第三方庫、插件、知名博客總結(jié) 作者大灰狼的小綿羊哥哥關(guān)注 2017.06.26 09:4...
    肇東周閱讀 15,022評論 4 61
  • ********《MVC模式下的購物車》******** ViewController: 購物車界面 整個(gè)界面就是...
    帶你去旅行閱讀 4,882評論 4 21
  • 轉(zhuǎn)載鏈接 注:本文轉(zhuǎn)載知乎上的回答 作者:初雪 鏈接:https://www.zhihu.com/question...
    pengshuangta閱讀 29,274評論 9 295
  • 孤獨(dú)的夜 唯有時(shí)光悄悄流瀉 而流瀉的時(shí)光里 總有些年少的心在風(fēng)中搖曳 搖曳 然后毀滅 之后 歲月更迭 是否有人 為...
    須臾331閱讀 178評論 0 1
  • 8.8 工作充實(shí) 看了一集快樂大本營很快樂 竇靖童
    來瑩瑩閱讀 277評論 0 0

友情鏈接更多精彩內(nèi)容