I am trying to redirect to a different view controller when a user clicks on a picture that is part of a cell


It is not redirecting to the VC I want it to. It is not even registering the click. I tested this with a print statement. Here is the code. The function giving me the problem is the last one of the code




It is a bit hard to read in the small editor window.

Where should the click be registered ?

Note: your classes names should begin with Uppercase.


The click should be registered when the user clicks the picture. This is the function

Code Block
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
print("clicked did select")
// send post uuid to "postuuid" variable
postuuid.append(uuidArray[indexPath.row])
// navigate to post view controller
let post = self.storyboard?.instantiateViewController(withIdentifier: "postVC") as! postVC
self.navigationController?.pushViewController(post, animated: true)
}


I have a problem finding my way in the code.

In viewDidLoad, you add a subView. Seems it covers completely the collectionView (addSubView adds to the top) ?
When you tap on the image, the tap is intercepted.

Try to addSubView behind collectionView with insertSubview(_:belowSubview:)

Should I add that instead of
Code Block
collectionView?.addSubview(refresher)

That did not work. Could it be because the tap gets intercepted by some of the gesture recognizers. I have 3 in local scope inside the class but not inside a function.

Code Block
let postsTap = UITapGestureRecognizer(target: self, action: #selector(homeVC.postsTap))
postsTap.numberOfTapsRequired = 1
header.posts.isUserInteractionEnabled = true
header.posts.addGestureRecognizer(postsTap)
let followersTap = UITapGestureRecognizer(target: self, action: #selector(homeVC.followersTap))
followersTap.numberOfTapsRequired = 1
header.followers.isUserInteractionEnabled = true
header.followers.addGestureRecognizer(followersTap)
let followingsTap = UITapGestureRecognizer(target: self, action: #selector(homeVC.followingsTap))
followingsTap.numberOfTapsRequired = 1
header.followings.isUserInteractionEnabled = true
header.followings.addGestureRecognizer(followingsTap)
return header

I am trying to redirect to a different view controller when a user clicks on a picture that is part of a cell
 
 
Q