iOS中如何通过点击UITableViewCell中的Button来获取当前Cell的indexPath

第一种:

- (void) btnOnClickTouched:(UIButton *)aButton

// WTAVViewCell * myCell = (myTableViewCell *)[aButton superView]; //表示Button添加在了Cell中。

    //如果将Button添加在myCell.contentView 中,

   WTAVViewCell * myCell = (WTAVViewCell *)[[btn superview] superview] ;

    

    NSIndexPath *indexPath = [self.tableView indexPathForCell:myCell];

    

    NSLog(@"%ld  %ld",indexPath.row,indexPath.section);

}

第二种:

[cell.button addTarget:self action:@selector(handMarkTagAction: event:) forControlEvents:UIControlEventTouchUpInside];

- (void)deleBtnclick:(UIButton *)btn event:(UIEvent *)event{

//    NSSet *touches = [event allTouches];

//    UITouch *touch = [touches anyObject];

//    CGPoint currentTouchPosition = [touch locationInView:self.tableView];

//    NSIndexPath *indexPath =[self.tableView indexPathForRowAtPoint:currentTouchPosition];

猜你喜欢

转载自blog.csdn.net/a18339063397/article/details/88026117