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 trialAlex Cevallos
16,551 PointsUICollectionViewCell 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
dantesolis
8,842 PointsHey 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.
Andrew Boryk
15,916 Pointshttp://stackoverflow.com/questions/11013587/differences-between-strong-and-weak-in-objective-c
Awesome answer to this question, I deserve no credit lol
Alex Cevallos
16,551 PointsHey! 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
dantesolis
8,842 PointsOK 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.
Alex Cevallos
16,551 PointsAh makes sense.. but UICollectionViewCell has a view ?
Alex Cevallos
16,551 PointsAlex Cevallos
16,551 PointsThank you very much for your responses!! helped out a lot
dantesolis
8,842 Pointsdantesolis
8,842 PointsNo problem man, glad I was able to help.