zoukankan      html  css  js  c++  java
  • iOS UITableView获取cell的indexPath及cell内部按钮点击事件处理

    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *cellID = @"test";
    
    testCell *cell = (testCell *)[tableView dequeueReusableCellWithIdentifier:cellID];
    
    if (!cell) {
        cell = [[[NSBundle mainBundle]loadNibNamed:@"testCell" owner:self options:nil]lastObject];
    }
    
    cell.testLabel.text = self.data[indexPath.row];
    //添加按钮点击事件
    [cell.testBtn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    
    return cell;
    }
    //按钮点击事件
    -(void)click:(UIButton *)btn{
    
    UIView *contentView = [btn superview];
    testCell *cell = (testCell *)[contentView superview];
    NSIndexPath *indexPath = [self.tb indexPathForCell:cell];
    
    NSLog(@"%@----%@",indexPath,self.data[indexPath.row]);
    }
  • 相关阅读:
    Majority Element
    Longest Increasing Subsequence
    Count Primes
    Valid Parentheses
    Largest Rectangle in Histogram
    Linked List Cycle II
    Linked List Cycle
    Evaluate Reverse Polish Notation
    Longest Valid Parentheses
    适配总结
  • 原文地址:https://www.cnblogs.com/huihuizhang/p/15427693.html
Copyright © 2011-2022 走看看