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
Paul Cisneros
Courses Plus Student 2,117 PointsPhotoBombers - Stage 4 - Introducing Gesture Recognizers - Alert "Liked" not working
Here is my code for the two methods updated/created in this video:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.imageView = [[UIImageView alloc] init];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(like)];
tap.numberOfTapsRequired = 2;
[self addGestureRecognizer:tap];
[self.contentView addSubview:self.imageView];
}
return self;
}
- (void)like {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Liked!" message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
[alert show];
double delayInSeconds = 1.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[alert dismissWithClickedButtonIndex:0 animated:YES];
});
}
When I tap on a collection view cell, or a photo, in the simulator I'm not getting an alert like in the video. In fact, nothing happens at all. Even in the console.
I did notice that when I was typing in the 'dispatch_time' block of code, Xcode did not code complete like in the video.
Xcode instead gave me this:
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(<#delayInSeconds#> * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
<#code to be executed after a specified delay#>
});
Which is different from the video.
I actually copy and pasted the code from the video from the project file at this stage into my own project.
Now I'm stuck at this point. Anyone else having this same issue?
1 Answer
Paul Cisneros
Courses Plus Student 2,117 PointsNevermind, I figured it out.