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 With an Image

UICollectionViewCell imageView property is strong, why?

At 1:03 sam declares the UIImageview property for the cell as strong, is there any reason to this? I thought the ui elements are meant to be declared as weak, since they are dependent on the parent (strong) view

thanks in advance

3 Answers

Hey Alex,

I think it acts more like an empty picture frame, where you put something else inside.The Xcode documentation tells me :

A UICollectionViewCell object presents the content for a single data item when that item is within the collection view’s visible bounds.

So I think it just holds the view, or data type you want to show, but only that.

Thank you very much for your responses!! helped out a lot

No problem man, glad I was able to help.

Hey! thanks for the response but unfortunately I was wondering as to why this specific subview (the imageView) was strong instead of weak

even the stack overflow question states that subviews should be weak

OK I don't know if this entirely correct, but this is how I understand it :

  • "strong" pointers keep objects alive for as a long as there is a value inside them
  • "UICollectionViewCell" is a blank canvas [vid at 0:50min mark], it only holds a blank space where I can put something else inside.
  • the "imageView" property I just created, contains a pointer to an "UIImageView" object with a strong reference and therefore acts as the owner of that "UIImageView" object.

And that's what I want, I want the "UIImageView" object to be alive for as long as there's a value inside the "imageView" so as to be able to display it inside the "UICollectionViewCell". In this case, the "UICollectionViewCell" is dependant on that "UIImageView" which in turn is dependant on the "imageView".

I don't know if this answers your question or if it's entirely correct, but like I said, that's how I understood the whole thing.

Ah makes sense.. but UICollectionViewCell has a view ?