点击屏幕获取对应tableviewcell
-convertPoint: toView:获取试图坐标系之间的坐标变换
[UITableView indexPathForRowAtPoint:] 获得行序列号
例如:
- (IBAction)cellButtonTapped:(id)sender {
UIButton *button = sender;
CGPoint correctedPoint =
[button convertPoint:button.bounds.origin toView:self.tableView];
NSIndexPath *indexPath =
[self.tableView indexPathForRowAtPoint:correctedPoint];
NSLog(@"Button tapped in row %d", indexPath.row);
}
可以做成tableview的一个范畴:
- (NSIndexPath *)prp_indexPathForRowContainingView:(UIView *)view {
CGPoint correctedPoint = [view convertPoint:view.bounds.origin
toView:self];
return [self indexPathForRowAtPoint:correctedPoint];
}