single and double taps on UITableView

Discussion in 'iOS Programming' started by straber, Jul 25, 2012.

  1. straber macrumors member

    Joined:
    Jul 3, 2012
    #1
    I have a subclass of UITableView which I want to perform a different action depending on whether the user single taps a cell or double taps. The problem is that the double tap causes both events to fire.

    I'm handling it like this:

    Code:
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
        if(((UITouch *)[touches anyObject]).tapCount == 2) {
            wasDoubleTap = YES;
            NSLog(@"double tap");
        }
        else {
            wasDoubleTap = NO;
            NSLog(@"single tap");
        }
        [super touchesEnded:touches withEvent:event];
    }
    and double tapping causes "single tap" and then "double tap" to print out.

    Does anyone know of any way I can suppress the single tap to see if it's actually a double tap?

    Thanks.
     
  2. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #2
    Why not use gesturerecognizers instead? Much more stable and were released because the touchesBegan is "so so.."
     
  3. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #3
    These days one does this by using gesture recognizers. You create a single tab and a double tap gesture recognizer. If are only interested in the double tap you make the single tap recognizer fail if the double tap recognizer succeeds.
     

Share This Page