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

How do add a new collection in the collectionView & register a cell in viewDidLoad with the class? using the word photo?

We want to dequeue new collection view cells in the collectionView property of this class. Before we can do that, register a cell in viewDidLoad with the class THPhotoCell. Use the identifier "Photo".

im guess i start with

registerclass; [ uicollecetionviewcellclass ]

forcellwithreuseidentifier: @"photo"

im not to sure how to finish this one?

Stone Preston
Stone Preston
42,016 Points

remember that capitalization matters in objective c, so currently your method calls are incorrect since they dont use camel case. Your also have some invalid syntax in your code.

capitalization *

{} *

but what about ViewDidLoad: am i way off?

Stone Preston
Stone Preston
42,016 Points

looking at the code you posted in your original post you are heading in the right direction, but pretty far off still. Again since you appear to be struggling with basic syntax and concepts I recommend you do the objective c basics course first. If you keep doing this course and don't really have any idea whats going on you aren't going to learn anything.

ok,

3 Answers

Jose Andrade-Sinning
seal-mask
.a{fill-rule:evenodd;}techdegree
Jose Andrade-Sinning
Python Web Development Techdegree Student 12,676 Points

Sam,

There seems to be something wrong with this challenge. I'm doing exactly what you are asking and I still can't get through. Here is my code.

#import "SuperCoolViewController.h"
#import "THPhotoCell.h"

@implementation SuperCoolViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    /* Write your code below this line */
    [self.collectionView registerClass:[THPhotoCell class] forCellWithReuseIdentifier:@"Photo"];
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Photo" forIndexPath:indexPath];    
    return cell;
}
@end
Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

The challenge has only one task which is to dequeue new collection view cells in the collectionView. You don't need the cellForItemAtIndexPath method just the code within the viewDidLoad method.

Jose Andrade-Sinning
seal-mask
.a{fill-rule:evenodd;}techdegree
Jose Andrade-Sinning
Python Web Development Techdegree Student 12,676 Points

Thanks Amit, I was thrown off course by the comment above that suggests using "dequeueReusableCellWithReuseIdentifier:forIndexPath: in cellForItemAtIndexPath:." This is a lot simpler than what it appears. I suggest rewording the challenge instructions or adding some additional comments to clarify.

Sam Soffes
STAFF
Sam Soffes
Treehouse Guest Teacher

Checkout the UICollectionView reference. You'll need registerClass:forCellWithReuseIdentifier: in viewDidLoad and dequeueReusableCellWithReuseIdentifier:forIndexPath: in cellForItemAtIndexPath:.