通过cell中的button获取cell的IndexPath

2018-01-11  本文已影响11人  丶小裤头灬

通过cell中的Button来获取这个Cell的IndexPath

[cell.btn addTarget:self action:@selector(cellBtnClicked:event:) forControlEvents:UIControlEventTouchUpInside];

- (void)cellBtnClicked:(id)sender event:(id)event {
    NSSet *touches =[event allTouches];
    UITouch *touch =[touches anyObject];
    CGPoint currentTouchPosition = [touch locationInView:_tableView];
    NSIndexPath *indexPath= [_tableView indexPathForRowAtPoint:currentTouchPosition];
    if (indexPath!= nil) {
        // do something
    }
}
上一篇 下一篇

猜你喜欢

热点阅读