Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

I'm a Mac

macrumors 6502
Original poster
Nov 5, 2007
436
0
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];
	}
	
}
 

SqueegyX

macrumors regular
Mar 24, 2008
108
1
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.