iOS 逆向获取cell的IndexPath

场景如图:

iOS 逆向获取cell的IndexPath_第1张图片
定位Cell.png

在代理方法-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath中执行下列方法:

#pragma mark - 下面是在控制器中进行判断的
//某个cell中的按钮触发 - wsx注释
-(void)clickBtnOnCell:(UIButton *)sender event:(UIEvent *)event{
    NSSet *touches = [event allTouches];
    UITouch *touch = [touches anyObject];
    CGPoint point = [touch locationInView:tableView];
    NSIndexPath *indexPath = [tableView indexPathForRowAtPoint:point];

    NSLog(@"cell.indexPath.row=%ld-------------",(long)indexPath.row);
}

这样就可以获取到任意Cell的IndexPath值了。

你可能感兴趣的:(iOS 逆向获取cell的IndexPath)