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 Build a Photo Browser iPhone App Gestures Creating a Detail View Controller

Show image when clicked in new VC from Parse!

So I want to do exactly all this, except all my pictures are in parse. And I think my problem is the code in PhotoController.h and .m, what code do I need to write so when I click each individual cell, it will get bigger, THANKS FOR THE HELP

PhotoController.h

#import <Foundation/Foundation.h>
#import <Parse/Parse.h>

@interface PhotoController : NSObject

@property (nonatomic) NSArray *photos;

+ (void)imageForPhoto:(NSDictionary *)photo size:(NSString *)size completion:(void(^)(UIImage *image))completion;

@end

PhotoController.m

#import "PhotoController.h"

@implementation PhotoController

+ (void)imageForPhoto:(NSDictionary *)photo size:(NSString *)size completion:(void(^)(UIImage *image))completion {
    if (photo == nil || size == nil || completion == nil) {
        return;
    }


    PFQuery *query = [PFQuery queryWithClassName:@"Photo"];

    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (!error) {
            NSLog(@"%d", objects.count);
        }
    }];

}

@end

5 Answers

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Hi Jonah,

Where are you calling this code from? Can you paste in the code from your inbox? Are you performing a segue to this view controller? I'm confused as to why this would be a static class method (+ instead of -).

Well, here is my DetailViewController.m. So after you click on each cell, it will go here.

@interface SeparateImageViewController ()

@property (nonatomic) UIImageView *userImageView;


@end

@implementation SeparateImageViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.95];

    self.userImageView = [[UIImageView alloc] init];
    [self.view addSubview:self.userImageView];

    self.userImageView.image = _image;

//    [PhotoController imageForPhoto:self.photo size:@"standard_resolution" completion:^(UIImage *image) {
//        self.userImageView.image = image;
//    }];

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(close)];
    [self.view addGestureRecognizer:tap];
}

-(void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];

    CGSize size = self.view.bounds.size;

    CGSize imageSize = CGSizeMake(size.width, size.width);
    self.userImageView.frame = CGRectMake(0.0, (size.height - imageSize.height) / 2.0, imageSize.width, imageSize.height);
}

-(void)close {
    [self dismissViewControllerAnimated:YES completion:nil];
}

@end

And here is the PhotoCell.m

@implementation PhotoCell

@synthesize parseImage;

-(void)setPicture:(NSDictionary *)picture {
    _picture = picture;

//    [PhotoController imageForPhoto:_picture size:@"thumbnail" completion:^(UIImage *image) {
//        self.imageView.image = image;
//    }];

}


- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.imageView = [[PFImageView alloc] init];



        [self.contentView addSubview:self.imageView];
    }
    return self;
}


-(void)layoutSubviews {
    [super layoutSubviews];

    self.imageView.frame = self.contentView.bounds;

}

@end

So once again, I want to click on a cell in a collectionview and have it go to a different view controller, like instagram

By the way, here is my didSelectItemAtIndexPath in my collection view class:

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    NSDictionary *photo = self.photos[indexPath.row];
    SeparateImageViewController *viewController = [[SeparateImageViewController alloc] init];
    viewController.modalPresentationStyle = UIModalPresentationCustom;
    viewController.transitioningDelegate = self;
    viewController.photo = photo;

    [self presentViewController:viewController animated:YES completion:nil];
}
Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

So sorry for my late reply here. Are you still having trouble with this? Where exactly is it breaking?