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 trialRohan A.
4,008 PointsCompiler 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
20,444 PointsAh, 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!
Matthew Mascioni
20,444 PointsWhich error are you getting?
Rohan A.
4,008 PointsBummer! There is a compiler error. Please click on preview to view your syntax errors!
Rohan A.
4,008 PointsRohan A.
4,008 PointsThank you. I misunderstood Sam Soffes's comment in this thread.