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 Displaying API Data with Collection Views in Objective-C Introduction to CollectionViews Styling our UICollectionView and Cells

Lucas Santos
Lucas Santos
181 Points

Hello, I am trying to add the cell.imageView etc.... but imageView is not available to be chosen.. where can I find it?

Hello, I am trying to add the cell.imageView etc.... but imageView is not available to be chosen.. where can I find it?

2 Answers

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

// The imageView not found because your cell  subclass of (UICollectionViewCell),  so change it to your  custom cell
class
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];

    // Configure the cell

    cell.imageView.image = [UIImage imageNamed:@"a"];
    return cell;
}

change The cell code from UICollectionViewCell to name of your custom cell, like this:

CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];

If this is a collection view you working with you need to create a collection view cell. A collection view cell does not have any default properties like say a tableview cell does.