UITableViewCell上的UILongPressGestureRecognizer – 双重调用

我在单元格中使用UILongPressGestureRecognizer。 我需要的是:当用户点击一个单元格1.0秒,调用一个视图控制器。 如果用户点击该单元,则另一个VC。

我可以通过使用UILongPressGestureRecognizer来完成。 但问题是,调用viewController两次。

码:

if (indexPath.section == 0 && indexPath.row == 1){ UILongPressGestureRecognizer *longPressTap = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(memberListWithSearchOptions)]; longPressTap.minimumPressDuration = 1.0; [cell addGestureRecognizer:longPressTap]; [longPressTap release]; } 

我认为我需要的是在识别LongPress之后,禁用识别器,直到tableView再次出现在屏幕上。

我怎样才能做到这一点?

谢谢,

RL

如果状态是UIGestureRecognizerStateBegan (或UIGestureRecognizerStateEnded ),您可能需要做的是检查手势识别器的state属性,并仅显示下一个视图控制器。

你需要改变你的方法来接受手势识别器作为参数(并且更新@selector参数)并检查它的状态:

 UILongPressGestureRecognizer *longPressTap = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(memberListWithSearchOptions:)]; //colon at end //... - (void)memberListWithSearchOptions:(UILongPressGestureRecognizer *)lpt { if (lpt.state == UIGestureRecognizerStateBegan) //or check for UIGestureRecognizerStateEnded instead { //display view controller... } } 

你必须检查下面的状态

 - (void)memberListWithSearchOptions:(UILongPressGestureRecognizer*)sender { if (sender.state == UIGestureRecognizerStateEnded) { NSLog(@"UIGestureRecognizerStateEnded"); //Do Whatever You want on End of Gesture } else if (sender.state == UIGestureRecognizerStateBegan){ NSLog(@"UIGestureRecognizerStateBegan."); //Do Whatever You want on Began of Gesture }