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 UIKit Dynamics Extra Credit

Add checkmarks to UICollectionViewCell

I am looking to add checkmarks to the subclass of UICollectionViewCell that I have implemented for the photo bombers app.

My understanding is that, unlike with the UITableView class, there is no checkMarkAccessoryType method that provides default checkmarks.

Therefore, I went online and found this custom implementation: http://stackoverflow.com/questions/18977527/how-do-i-display-the-standard-checkmark-on-a-uicollectionviewcell

However, I cannot connect the dots and am unable to display at least the "unchecked" checkmarks on my UICollectionViewController.

Still in the beginning of my iOS learning curve and would value and appreciate guidance from more experienced coders.

I'd be happy to share my code with anyone willing to work with me on this.

Thanks!

1 Answer

That StackOverflow post you found looks like a good one to feed off of. What I think you need to do (someone else feel free to correct me if I'm wrong) is you should drag in a new UIView (which will be where your checkmark appears) to your custom UICollectionViewCell xib (or in your storyboard) and set the UIView to be of type SSCheckMark. Then, all you need is an instance variable in your UICollectionViewCell subclass that references the new view, so make a new IBOutlet in your subclass and connect it up with your new UIView. Now, from looking at the code on StackOverflow, all you need to do at the start is set the view's checkmark style (using setCheckMarkStyle), and then toggle whether or not it's checked (using setChecked) whenever the user taps on the cell. Hope that helps!