Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Build a Photo Browser iPhone App Gestures Triple-Tap Gesture Recognizer.

Ryan Oldford
Ryan Oldford
11,992 Points

Photo Bombers Stage 4 Code Challenge problems

I'm having a problem with the triple-tap gesture recognizer code challenge. My code seems fine, but it's saying there's a compiler error (with no other explanation). What am I doing wrong?

Here's my code:

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(like)];
tap.numberOfTapsRequired = 2;
[self addGestureRecognizer:tap];

Edit: Okay, I've tried everything now and it's still not working:

  • I actually had set numberOfTapsRequired to 3, but I forgot to write it in here.
  • I've used self and self.view in both the first and third line (every combination)
  • I've tried using @selector(like), @selector(like:), and nil in line 1.
  • I've even tried removing line 3, since it's not really in the instructions as written.

Nothing has worked, and every time I just get "compiler errors" in the code challenge. I'm beginning to think that something on the backend is broken. Is there something stupid that I've missed? I can't see how I'm doing anything wrong...

Edit 2: Turns out the answer was very simple. I was copying from the Xcode files I'd been making as I followed along with the videos, and it turns out that was going beyond what the Code Challenge was asking for. You LITERALLY just need to alloc/init the UITapGestureRecognizer and set numberOfTapsRequired. Nothing else! :)

3 Answers

Thomas Nilsen
Thomas Nilsen
14,957 Points

Also, I you want to be able to triple tap, set the tap.numberOfTapsRequired = 3, not 2 :)

Guillaume Maka
Guillaume Maka
Courses Plus Student 10,224 Points
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(like:)];

you forgot the ":" after "like"

I think you need to add the Gesture to the view, therefore the last line of code needs a small tweak [self.view addGestureRecognizer:tap] .