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.
Rashii Henry16,433 Points
adding ImageView to CollectionViewCell
I'm having a little trouble displaying an array of images at a specific index of each CollectionViewCell.
currently using : UILabel *itemLabel = (UILabel *)[cell viewWithTag:100]; itemLabel.text = [defaultBubblesArray objectAtIndex:indexPath.row]; //defaultBubblesArray is an array with strings.
&& the label works fine.
but when i try to do it with an UIImageView, button, or label, i either get an error or the images just don't show when the app loads.
Stone Preston42,016 Points
its best you use a custom collection view cell class. You wont have to mess with viewWIthTag if you do it with a custom cell class. Add a imageView to your collection view cell in storyboard then connect it up to your custom class's .h file. then just implement a few delegate methods like
- (UICollectionViewCell *) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath - (CGFloat) collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section - (CGFloat) collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
and set the cells imageView property that you added in the custom class in the cellForItemAtIndexPath