我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。知道为什么吗?