方法一:
在表格的某行添加按钮时,可以根据一下方法获取到表格的NSIndexPath
- (void)btnClicked:(id)sender event:(id)event{ NSSet *touches = [event allTouches]; UITouch *touch = [touches anyObject]; CGPoint currentTouchPosition = [touch locationInView:[self myTableView]]; NSIndexPath *indexPath = [[self myTableView] indexPathForRowAtPoint:currentTouchPosition]; //do something}方法二:
- (void)cellBUttonTapped:(id)sender{ UIButton *button = sender; CGPoint correctedPoint = [button convertPoint:button.bounds.origin toView:self.tableView]; NSIndexPath *indexPath = [self.tableView indexPathForAtPoint:correctedPoint]; NSLog(@"%d",indexPath.row);}