single and double taps on UITableView

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

  1. straber macrumors member

    Jul 3, 2012
    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:

    - (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?

  2. jnoxx macrumors 65816


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


    Sep 2, 2008
    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