iOS 逆向获取cell的IndexPath

场景如图:

定位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值了。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容