Welcome to the Treehouse Community
Looking to learn something new?
Ryan Oldford11,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! :)
Thomas Nilsen14,957 Points
Also, I you want to be able to triple tap, set the tap.numberOfTapsRequired = 3, not 2 :)
Guillaume MakaCourses 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] .