我在手势识别器选择器中接收右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.知道为什么?
答案 0 :(得分:0)
为每个 UITableViewCell 添加 UISwipeGestureRecognizer (使用相同的选择器)。然后,当调用选择器时,您可以通过以下方式获取单元格:sender.view
。