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.

iOS Build a Photo Browser iPhone App Gestures Introducing Gesture Recognizers

Nic Huang
PLUS
Nic Huang
Courses Plus Student 10,573 Points

Like specific photo

When we like a photo, we log photo's link and use its id as parameter to send request. But what I don't understand here is that how we can get specific photo's id and link by simply attaching a tap gesture on it. There is no "didSelect..." delegate method implemented, and we don't send any parameter in gesture's selector. How do we make certain the link and the parameter is the one I tapped??

1 Answer

Sam Soffes
STAFF
Sam Soffes
Treehouse Guest Teacher

We know which photo was double tapped since we add the gesture recognizer to the collection view cell. The cell already has a photo, so when there is a double tap in the cell, we know it's the photo that belongs to that cell.

Gesture recognizers use target-action instead of a didSelect delegate. That's why the like method gets called in the cell when you double tap.