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 Creating a Detail View Controller

Now a single tap opens each picture, I can't double-tap to 'Like' a picture.

Hi all,

I've been working through the Photo Bomber application with iOS and Instagram.

We added gesture functionality to spot a double-tap and to like the photo this was done on. Subsequently, we added a single tap to enlarge the pic into its own view, full-size.

In my app, the single tap overrides the double-tap so I can no longer 'Like' a pic.

Did I miss something?

Thanks,

Steve.

1 Answer

Adam Nieto
Adam Nieto
1,561 Points

In the THPhotoCell.m file you'll see the code below which indicates the like gesture was updated to be a long press instead of a double tap. Don't remember if this was covered in the course or not.

- (void)like:(id)sender {
    UILongPressGestureRecognizer *longPress = (UILongPressGestureRecognizer *)sender;
    if ( longPress.state == UIGestureRecognizerStateEnded) {
        NSURLSession *session = [NSURLSession sharedSession];
        NSString *accessToken = [[NSUserDefaults standardUserDefaults] objectForKey:@"accessToken"];
        NSString *urlString = [[NSString alloc] initWithFormat:@"https://api.instagram.com/v1/media/%@/likes?access_token=%@", self.photo[@"id"], accessToken];
        NSURL *url = [[NSURL alloc] initWithString:urlString];
        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
        request.HTTPMethod = @"POST";
        NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
            dispatch_async(dispatch_get_main_queue(), ^{
                [self showLikeCompletion];
            });
        }];
        [task resume];
    }
}