I have a UICollectionView with cells that hold images. I would like to make each individual cell of the UICollectionView touchable/clickable through code, how should I approach this?
Asked
Active
Viewed 457 times
1 Answers
0
You need to override the didSelectItemAt:
delegate method.
override func collectionView(_ collectionView: UICollectionView,
didSelectItemAt indexPath: IndexPath)
Attach the dataSource
and delegate
for the UICollectionView to your view controller class and implement that method.
In the indexPath
parameter, you can get the position of your cell and then perform whatever action you like programmatically. Like pushing a new ViewController etc.
This might be helpful in understanding how a UICollectionView works and how to control it from your ViewController class

varijkapil13
- 390
- 4
- 16