IOS 通过UITableView上的Button传递参数
来源:互联网 发布:淘宝客活动报名技巧 编辑:程序博客网 时间:2024/05/24 03:20
在做IOS项目时,经常会碰到需要自定义cell的情况,并且在cell上面有Button,点击Button的时候需要响应事件,这个我们可以需要传递一些参数,但是仅仅通过Button没有办法传递我们的参数,这个时候我们就需要找到承载Button的cell,通过cell传递一些参数。
下面介绍点击自定义的cell上面的Button传递一些参数,首先我们自定义一个cell,在cell中定义一下我们要传递的参数,在这里我们定义一个id,点击button事件的时候我们获取这个id,然后根据这个id去执行相应的操作,在Button点击的事件里面获取cell对象的方法有如下两种方法。
[cell.btnview addTarget:selfaction:@selector(viewdetailinfo:)forControlEvents:UIControlEventTouchUpInside];
方法一
-(void)viewdetailinfo:(UIButton *)sender{ CGRect btnRect=[[sender superview] superview].frame; //假设我们自定义的cell时FriendCell for(FriendCell *cell in [self.tableview visibleCells])//遍历cell { CGRect cellframe=cell.frame; if(CGRectIntersectsRect(btnRect, cellframe))//通过位置判断cell { //点击的button所在的cell,可以通过cell获取参数 } }}
方法二
-(void)viewdetailinfo2:(UIButton *)sender{ UIView * v=[sender superview]; FriendCell *cell=(FriendCell *)[v superview];//找到cell NSIndexPath *indexPath=[self.tableview indexPathForCell:cell];//找到cell所在的行}
以上两种方法可以传递cell上面自定义Button点击事件的参数。
- IOS 通过UITableView上的Button传递参数
- iOS -- 通过runtime向Button的点击方法里传递参数实现单选效果
- 【代码笔记】iOS-UITableView上的button点击事件
- EXTJS通过Button按钮向弹出的IFRAM窗口传递参数与获取参数
- UITableView 上添加button
- 如何通过代理之道UItableView上cell上面的button点击的是哪一行的
- button传递任意类型的参数
- UITableView cell上的button和label问题
- UITableView上button的点击事件(一)
- IOS-UITableView上的纯代码实现
- NGUI Button Message传递参数
- 待解决的问题 -------button下的参数传递!
- Unity3D和IOS的交互教程——通过URL启动APP并传递参数
- Unity3D和IOS的交互教程——通过URL启动APP并传递参数
- 巧用Button的Command事件,用CommandArgument来传递参数
- Silverlight button可以用来传递参数的属性
- android 的button响应及(Intent,Bundle)传递参数
- Javascript中button按钮的onclick()事件传递参数
- css 设置display:none 后用js获取值为空
- apt-get -f install 错误的处理
- 虚析构函数、纯虚析构函数
- 我的LFS之旅!!!!!!!
- Difference between ConcurrentHashMap and Collections.synchronizedMap and Hashtable in Java
- IOS 通过UITableView上的Button传递参数
- 数据库优化之系统设计方面思考
- What is the difference between Enumeration and Iterator ?
- Linux NAT共享上网脚本
- spark中的action和transformation
- 百度图片api
- Why String is immutable or final in Java
- 数据库优化之 数据库不同应用方向优化
- 正则表达式