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]);
}
原文地址:https://www.cnblogs.com/huihuizhang/p/15427693.html