help with touchesEnded

Discussion in 'iOS Programming' started by I'm a Mac, Sep 30, 2008.

  1. I'm a Mac macrumors 6502

    Joined:
    Nov 5, 2007
    #1
    I want my application to display a different alert the on the 1st touch, the 3rd touch, and the 5th touch, but every time I tap the screen after hitting OK on the alert for the first touch, it displays the alert for the 1st touch again.

    Code:
     - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
        UITouch* touch = [touches anyObject];
        NSUInteger numTaps = [touch tapCount];
        if (numTaps == 1 ) {
    		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Tap #1" message:@"You have tapped once" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    		[alert show];
    	[alert release];	} 
    	if (numTaps == 3)  {
    			UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Tap #3" message:@"You have tapped three times. " delegate:self cancelButtonTitle:@"OK otherButtonTitles:nil];
    		[alert show];
    	[alert release];	} 
    	
    	if (numTaps == 5) {
    		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Tap #5" message:@"You have tapped five times " delegate:self cancelButtonTitle:@"OK." otherButtonTitles:nil];
    		[alert show];
    		[alert release];
    	}
    	
    } 
    
     
  2. mauszozo macrumors newbie

    Joined:
    Sep 25, 2008
    #2
  3. I'm a Mac thread starter macrumors 6502

    Joined:
    Nov 5, 2007
    #3
    arggghhh, I still can't get it too work right.
     
  4. SqueegyX macrumors regular

    Joined:
    Mar 24, 2008
    #4
    TouchesBegan/Moved/Ended all report the number of touches that did something, not all touches. So if you have 3 fingers on the screen, and lift one up, the variable "touches" will have a single touch object in it, representing the touch that was lifted. Sometimes they are reported together, but you can't count on that.
     

Share This Page