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