OC开发资料收集区iOS 常见问题汇总

iOS 逆向获取cell的IndexPath

2017-07-14  本文已影响67人  oc123

场景如图:

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

上一篇 下一篇

猜你喜欢

热点阅读