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 Collection Views Implementing a Custom UICollectionViewCell

Compiler Error - collectionView property

I hate to ask a question which is not specific. I am getting a compiler error. Please advise where I am going wrong?

- (void)viewDidLoad {
    [super viewDidLoad];

[self.collectionView registerClass:[THPhotoCell class] forCellWithReuseIdentifier:@"Photo"];

}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 

{    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Photo" forIndexPath:indexPath];

return cell;

}

2 Answers

Matthew Mascioni
Matthew Mascioni
20,444 Points

Ah, okay, I see what's going wrong (though that is a pretty un-informative error)

The question only asks us to register a cell in viewDidLoad with the class THPhotoCell. None of the UICollectionView delegate methods are necessary for this code challenge. But, the compiler isn't understanding the extra code.

Your code in viewDidLoad is perfect-- just remove the

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 

{    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Photo" forIndexPath:indexPath];

return cell;

}

from your answer and you should be good to go!

Thank you. I misunderstood Sam Soffes's comment in this thread.

Bummer! There is a compiler error. Please click on preview to view your syntax errors!