UITongPress上的UILongPressGestureRecognizer - 双重调用 [英] UILongPressGestureRecognizer on UITableViewCell - double call

查看:106
本文介绍了UITongPress上的UILongPressGestureRecognizer - 双重调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using the UILongPressGestureRecognizer in a cell. What I need is: when a user taps a cell for 1.0 seconds, call one view controller. If the user taps the cell, another VC.

我可以通过使用UILongPressGestureRecognizer来实现这一点。但问题是调用viewController两次。

I can accomplish that by using the UILongPressGestureRecognizer. But the issue is that is calls the viewController twice.

代码:

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再次出现在屏幕上。

I think that what I need is, after recognizing the LongPress, disable the recognizer, until the tableView appears again on screen.

我该怎么做?

谢谢,

RL

推荐答案

您可能需要做的不是禁用它检查手势识别器的状态属性,如果状态为 UIGestureRecognizerStateBegan (或<$ c $),则仅显示下一个视图控制器c> UIGestureRecognizerStateEnded )。

Instead of disabling it, what you probably need to do is check the gesture recognizer's state property and only display the next view controller if the state is UIGestureRecognizerStateBegan (or UIGestureRecognizerStateEnded).

您需要更改方法以接受手势识别器作为参数(并更新 @选择参数),并检查其状态:

You'll need to change your method to accept the gesture recognizer as a parameter (and also update the @selector parameter) and check it's state:

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...
    }
}

这篇关于UITongPress上的UILongPressGestureRecognizer - 双重调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆