UILongPressGestureRecognizer on UITableViewCell - double call

前端 未结 2 1292
情歌与酒
情歌与酒 2020-12-10 19:47

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

2条回答
  •  抹茶落季
    2020-12-10 20:30

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

提交回复
热议问题