UITableView获取当前选中的控件的indexPath

通到取得在tableView中的位置,取得所在indexPath

- (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);
}


//获取当前选中的控件的indexPath
- (NSIndexPath *)cellButtonTapped:(id)sender {
UIView *view = sender;
CGPoint correctedPoint = [view convertPoint:view.bounds.origin toView:_tableView];
return [_tableView indexPathForRowAtPoint:correctedPoint];
}



- (UITableViewCell *)tableViewCellForView:(UIView *)view
{
UIView *tempView = view;
while (![tempView isKindOfClass:[UITableViewCell class]]) {
tempView = tempView.superview;
}
return (UITableViewCell *)tempView;
}

你可能感兴趣的:(iPhone,iOS,Objective-c)