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];

}

购物车界面,不同section,点击增减物品,确定取消选中的逻辑判断的更多相关文章

  1. JAVA面向对象编程之购物车界面的设计与功能的实现

    1.小组成员及分工 小组成员 负责工作 兰泽祥 负责总体界面.Git代码库 吴修恩 负责MVC模式.类名包名的规范化 2.Git 仓库地址 仓库地址:https://gitee.com/lanzexi ...

  2. ContactDetail 和 ContactEditor 界面头像响应点击过程

    1,联系人详情界面 ContactDetailFragment中处理,ViewAdapter装载数据显示头像 private final class ViewAdapter extends BaseA ...

  3. 在用easyui中做CRUD功能时,当删除一行或多行数据后再点击修改会提示你选中了多行,如何解决这个bug了?

    在用easyui中做CRUD功能时,当删除一行或多行数据后再点击修改会提示你选中了多行,如何解决这个bug了? 在删除成功后,加上这句话就可以了:$("#dg").datagrid ...

  4. jquery 复选框全选/全不选切换 普通DOM元素点击选中/取消选中切换

    1.要选中的复选框设置统一的name 用prop() prop() 方法设置或返回被选元素的属性和值. $("#selectAll").click(function(){ $(&q ...

  5. input选中 和 select点击下拉选择获取选中选项的值

    1.input选中$('#checkBox').find('input').each(function(i){ if($(this).prop('checked')){//获取是否选中 并判断 $(t ...

  6. Android Splash界面支持用户点击 直接进入主界面

    转载请注明出处:http://blog.csdn.net/lmj623565791/article/details/23613403 现在大部分APP都有Splash界面,下面列一下Splash页面的 ...

  7. unigui ios微信界面错位和点击失灵问题

    IOS微信下会出现二个严重问题: 1.输入框失去焦点导致控件错位,造成无点正常点击. 此问题是微信自带浏览器,一直遗留问题, 尝试了多种方法始终无解.因此要用来开发公众号的一定要注意. 2.界面下移 ...

  8. linux系统(CentOS7)虚拟机上安装oracle 11g,解决oracle图形界面卡住无法点击next问题

    https://www.cnblogs.com/nichoc/p/6416475.html

  9. 2-微信小程序开发(开发界面说明,按钮点击切换显示内容)

    说一个功能,大家在用微信实现控制设备的时候,是不是都在为绑定设备发愁. 我看了很多厂家的微信控制,大部分都只是可以用微信给设备配网,但是没有做用微信绑定的. 一般做绑定都是用设备的MAC地址. 这里我 ...

随机推荐

  1. Python第十二章正则表达式(2)

    1.前提是引入import re 匹配邮箱后缀需要写入r=r'\.com\.cn|\.com|\.cn' r=r'(\w+@\w+(\.com\.con|\.com|\.cn))'ll=re.find ...

  2. 12. Binary Tree Postorder Traversal && Binary Tree Preorder Traversal

    详见:剑指 Offer 题目汇总索引:第6题 Binary Tree Postorder Traversal            Given a binary tree, return the po ...

  3. centos 用dvd创建yum 仓库

    环境:CentOS 6.0 默认的yum是以网络来安装的,在没有网络或者网速不佳的情况下,通过yum来安装软件是意见非常痛苦的事情.其实对于CentOS DVD来说,里面提供的软件就足以满足我们的需要 ...

  4. Spring MVC入门知识总结

    2.1.Spring Web MVC是什么 Spring Web MVC是一种基于Java的实现了Web MVC设计模式的请求驱动类型的轻量级Web框架,即使用了MVC架构模式的思想,将web层进行职 ...

  5. mysql存储过程简介

    创建存储过程CREATE PROCEDURE productpricing(OUT pl DECIMAL(8,2),OUT ph DECIMAL(8,2),OUT pa DECIMAL(8,2))BE ...

  6. TListView的一些操作

    1,让滚动条滚动的API SetScrollPos int SetScrollPos(     _In_  HWND hWnd,     _In_  int nBar,     _In_  int n ...

  7. —linux 磁盘配额按用户管理(quota)

    我根据下面的ref链接整理的基本是的按用户额度管理步骤 (按组的额度管理被简化掉) 我在Ubuntu服务器12.04下整理,其他版本的Ubuntu和Linux应该都没有问题的 (有任何错误都指正给我, ...

  8. UVa 10071 - Back to High School Physics

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=s ...

  9. new String(“a”)与String a="a";

    String a=new String ("a"); String b=new String ("a"); //这是比较地址 System.out.printl ...

  10. C++ MFC获取软件运行目录 (包含软件名)

    TCHAR *path = new TCHAR[MAX_PATH];   GetModuleFileName(NULL,path,MAX_PATH); AfxMessageBox(path);