1

NSIndexPath在手势识别器选择器中接收权限有问题。在UITableViewController:viewDidLoad我初始化手势识别器时

UISwipeGestureRecognizer* rightSwipeGestureRecognizer = 
        [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRight:)];
rightSwipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
[self.tableView addGestureRecognizer:rightSwipeGestureRecognizer];

在手势处理程序中,我试图获取行索引:

- (void) swipeRight: (UISwipeGestureRecognizer *)gestureRecognizer
{
if (gestureRecognizer.state == UIGestureRecognizerStateEnded) {
    CGPoint swipeLocation = [gestureRecognizer locationInView:self.tableView];
    NSIndexPath *swipedIndexPath = [self.tableView indexPathForRowAtPoint:swipeLocation];
    NSInteger row = swipedIndexPath.row;
    NSLog(@"Row %d", swipedIndexPath.row);
}

CGPoint 是正确的,但行总是 0。知道为什么吗?

4

1 回答 1

0

UISwipeGestureRecognizer添加到每个UITableViewCell(具有相同的选择器)。然后,当调用选择器时,您可以通过以下方式获取单元格:sender.view

于 2012-12-09T00:59:49.883 回答