iOS 逆向获取cell的IndexPath

作者: oc123 | 来源:发表于2017-07-14 16:37 被阅读67次

场景如图:

定位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

    本文链接:https://www.haomeiwen.com/subject/clcohxtx.html