PDA

View Full Version : help with touchesEnded




I'm a Mac
Sep 30, 2008, 03:31 PM
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.

- (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];
}

}



mauszozo
Sep 30, 2008, 04:36 PM
There's some example code at:
http://developer.apple.com/iphone/library/samplecode/Touches/index.html

that shows exactly what you're trying to do, that might help.

I'm a Mac
Oct 2, 2008, 04:14 PM
arggghhh, I still can't get it too work right.

SqueegyX
Oct 2, 2008, 05:42 PM
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.