You want to be able to handle collection view events, such as taps.
Assign a delegate to your collection view. In some other cases, you may not even have to do that. All you may need to do is listen for those events in your cell classes and handle them right there.
Collection views have
properties that have to conform to the
UICollectionViewDelegate protocol. The
delegate object will then receive various delegation calls from the
collection view informing the delegate of various events, such as a cell
becoming highlighted or selected. You need to know the difference
between the highlighted and selected state of a collection view cell.
When the user presses her finger down on a cell in a
collection view but doesn’t lift her finger up, the cell under her
finger is highlighted. When she presses her finger
down and lifts her finger up to say she wants to perform an action on
the cell, that cell will then be selected.
Collection view cells of type
UICollectionViewCell have two very useful
selected, that get set to
YES when the cell becomes highlighted or
If all you want to do is change your cell’s visual
presentation when it becomes selected, you’re in luck, because cells of
UICollectionViewCell expose a
UIView that you can set to a valid view. This view will then get displayed on the screen once your cell becomes selected. Let’s ...