zoukankan      html  css  js  c++  java
  • 购物车界面,不同section,点击增减物品,确定取消选中的逻辑判断

    1、首先在自定义的cell中,创建两个代理方法

    @protocol shopCartDelegate <NSObject>

    -(void)shopCartDelegate:(ShopCartCell *)cell WithBtn:(UIButton *)btn;

    -(void)shopCartDelegateNum:(ShopCartCell *)cell WithBtn:(UIButton *)btn;

    @end

    @interface ShopCartCell : UITableViewCell

    @property(nonatomic,assign)id<shopCartDelegate>delegate;

    @end

    2、在viewcontroller中实现这两个代理方法

    shopCell.delegate = self;//遵循代理

     方法实现

    (1)选中和取消的代理方法

    -(void)shopCartDelegate:(ShopCartCell *)cell WithBtn:(UIButton *)btn

    {

        NSIndexPath *indexPath =[self.tableView indexPathForCell:cell];

        int couss=0 ;

        NSArray *array =self.array[indexPath.section];

        for (int i =0; i<array.count; i++) {

            ShopModel *model =array[i];   

            if (i==indexPath.row) {

                if (btn.selected) {

                    model.isSelected = @"true";  

                }else{

                   model.isSelected = @"false";

                }

            }

            if ([model.isSelected isEqualToString:@"true"]) {

                couss++;

            }

        }

    //判断section内的cell是否都被选中

        if (couss == array.count) {

            self.isonOff = NO;

        }else{

            self.isonOff = YES;

        }

        [self.tableView reloadData];

    }

    (2)增加减少

    -(void)shopCartDelegateNum:(ShopCartCell *)cell WithBtn:(UIButton *)btn

    {

        NSIndexPath *indexPath =[self.tableView indexPathForCell:cell];

        NSArray *array =self.array[indexPath.section];

        for (int i =0; i<array.count; i++) {

            ShopModel *model =array[i];

            if (i==indexPath.row) {

                if (btn.tag == 2000) {

                    model.num =[NSString stringWithFormat:@"%d",model.num.intValue+1];

                }else{

                    if (model.num.intValue == 1) { 

                    }else{

                    model.num =[NSString stringWithFormat:@"%d",model.num.intValue-1];

                    }

                }

            }

        }

        [self.tableView reloadData];

    }

  • 相关阅读:
    根据不同运行环境配置和组织node.js应用
    python下pip使用bug汇总
    python的虚拟环境
    nginx使用手册--nginx的命令行参数
    nginx使用手册--nginx.conf文件配置详解
    使用async读取异步数据
    [Bootstrap]组件(三)
    [Bootstrap]组件(二)
    [Bootstrap]组件(一)
    [javascript|基本概念|一元操作符]学习笔记
  • 原文地址:https://www.cnblogs.com/zhanghuanan/p/5276535.html
Copyright © 2011-2022 走看看