首页 > 其他 > 详细

通过UIButton的tag进行传参

时间:2015-06-15 10:43:52      阅读:133      评论:0      收藏:0      [点我收藏+]

在给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];
}

 

 

 

通过UIButton的tag进行传参

原文:http://www.cnblogs.com/txios/p/4576332.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!