一:如果你是自定义cell,新建 .xib,中的按钮为:AotuBtn
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//自定义代码
}
两种方式:
//获取点击cell的indexPath第一种方式
UITableViewCell *cell = (UITableViewCell *)[[[sender superview] superview] superview];
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
NSLog(@"indexPath is = %li",(long)indexPath.row);
//获取点击cell的indexPath第二种方式
UITableViewCell *cell = (UITableViewCell *)[[[sender superview] superview] superview];
CGPoint hitPoint = [cell convertPoint:CGPointZero toView:self.tableView];
NSIndexPath *hitIndex = [self.tableView indexPathForRowAtPoint:hitPoint];
NSLog(@"indexPath is = %li",(long)hitIndex.row);
二:如果你是用代码方式直接将控件(如UILabel、UIButton等)加到UITableView的cell中
UITableViewCell *cell = (UITableViewCell *)[btn superview];
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
NSLog(@"indexPath is = %i",indexPath.row);
其他相关文章:
获取tableView(UICollectionViewCell)中cell相对于(UICollectionView)tableView.superView的区域坐标(位置)
http://blog.csdn.net/www9500net_/article/details/52437987