Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

"Shaking Things Up" Extra Credit Help - Double Tap to clear text

I've been trying to finish the extra credit from shaking things up and I'm having a problem. I'm not sure how to code my program to be able to clear the text away after a double tap.

This is what I got so far:

//Detects touch events to display new predictions
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
self.predictionLabel.text = @"";
}

- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
if([touch tapCount] == 2){
        NSLog(@"Double tap detected!");
        predictionLabel.text = @"";
    }
    else if([touch tapCount] == 1   ){
        [self makePrediction];
    }
}

1 Answer

Amit Bijlani
STAFF
Amit Bijlani
Treehouse Guest Teacher

Your code is right. The goal was to encourage you to figure out how to access double tap. It's not the perfect solution for a real world application because the single tap event will always fire before the double tap. If this were a real world app then I would implement a swipe gesture to clear the text.

Amit, Thank you very much. That was the exact trouble I had run into. Double tapping would present, then erase the data. So I stuck with single tap to clear, and shake to present. The swipe gesture is something I will look into after the "Animate This" section. Maybe I could create something cool with it.

Thank you for teaching an amazing course, and replying to this post!