Clickable CollectionView [Help Wanted]
zacgibson21 opened this issue · 3 comments
zacgibson21 commented
I can not for the life of me get the click function working on a collectionView. I have tried adding the below close to both my cell class and the main view controller with no luck.
CardPartCollectionViewDelegte {
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
print("Please Print!!")
}
Any advice would be appreciated
Deleted user commented
Have you assigned the delegate property of the collection view in question?
A structure something like:
class MainViewController:UIViewController, UICollectionViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// set the delegate to self - this doesn't have to be in viewDidLoad, just wherever you are setting
// up the collection view's properties.
collectionView.delegate = self
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
print("Please Print!!")
}
// rest of the class code including
// other UICollectionViewDelegateMethods...
}
croossin commented
@zacgibson21 Have you solved this yet? Or are you still having trouble?
croossin commented
Closing due to inactivity. Let us know if you still are having this issue.