I want to add a tap event to my CollectionViewCell
and to pass there my cell
with the data it has. How can I achieve this?
Should this event be handled by my ViewController
or by CollectionViewCell
?
My ViewController
:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CollectionViewCell", for: indexPath) as! CollectionViewCell
cell.imgImage.image = imageArray[indexPath.row]
cell.url = "xhini"
return cell
}
My CollectionViewCell
:
class CollectionViewCell: UICollectionViewCell {
@IBOutlet weak var imgImage: UIImageView!
var url: String = "url"
}