通过UIButton的tag进行传参

在给UIbutton绑定target嘚时候会遇到传递参数的问题,但默认的参数是一个(id)sender

- (void)noteBtnClicked:(id)sender {
}

  其实就是UIButton自身,也就只能利用UIButton自身的属性进行传值,貌似也只有这一个tag可以办到

于是可以这样:

 1 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 2 {
 3     
 4     HomeVideoCell *cell = (HomeVideoCell *)[tableView dequeueReusableCellWithIdentifier:@"HomeVideoCell"];
 5     cell.selectionStyle = UITableViewCellSelectionStyleNone;
 6     
 7     
 8     NewsListModel *model = [self.contentArray objectAtIndex:indexPath.row];
 9     [cell setVideoCellWithModel:model];
10     
11     
12     cell.storeBtn.tag = [model.tId integerValue];
13     [cell.storeBtn addTarget:self action:@selector(storeBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
14     [cell.shareBtn addTarget:self action:@selector(shareBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
15     [cell.noteBtn addTarget:self action:@selector(noteBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
16     
17     
18     return cell;
19 }

利用

cell.storeBtn.tag = [model.tId integerValue];存储在tag上;
在相应方法里面就可以通过传入的button拿到tag
//收藏
- (void)storeBtnClicked:(UIButton *)sender {
    
    NSString *value = [NSString stringWithFormat:@"%ld",(long)sender.tag];
}

 

 

 

转载于:https://www.cnblogs.com/txios/p/4576332.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值