zoukankan      html  css  js  c++  java
  • 通过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];
    }
     
  • 相关阅读:
    [Python]计算豆瓣电影TOP250的平均得分
    [Golang]使用自建代理访问指定网站
    HDU 2689.Sort it-冒泡排序
    HDU 1728.逃离迷宫-BFS
    hihoCoder #1498.Diligent Robots
    POJ 2503.Babelfish-sscanf()函数+strcmp()函数+二分
    Codeforces 608 B. Hamming Distance Sum-前缀和
    Codeforces 608 A. Saitama Destroys Hotel
    sscanf()函数
    UVA 11461.Square Numbers
  • 原文地址:https://www.cnblogs.com/txios/p/4576332.html
Copyright © 2011-2022 走看看