iOS 逆向获取cell的IndexPath
2017-07-14 本文已影响67人
oc123
场景如图:

在代理方法-(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值了。