I've created my UICollectionView
programmatically and in this case my didSelectItemAtIndexPath
method does not call at all.
let collectionView = UICollectionView(frame: CGRect(x: 0, y: 0, width: CGRectGetWidth(self.view.frame), height: 360), collectionViewLayout: layout)
collectionView.delegate = self
collectionView.dataSource = self
collectionView.userInteractionEnabled = true
So, what is a problem? Why when I tap on the cells I do not get my response?
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
print("Selected Cell: \(indexPath.row)")
}
I just encountered this case.
Did you put a button or an interactive view in a collection view cell? Your touch is handled by it, then didSelect isn't called.
Turn off User Interaction Enabled property by Interface builder, or set false programmatically.
Be sure that you don't have UICollectionViewDelegate and UICollectionViewDelegateFlowLayout together.
i Know this may be late, but for the sakes of feature purpose, CollectionView[didSelectItem]
not responding to touch could be as a result of you also enalbing addGestureRecognizer
so check if you have set a gesture recognizer on your CollectionView
like so collectionView?.addGestureRecognizer(tapGestRecognizer)
check in UiCollectionviewCell
subclass isUserInteractionEnabled
property or set it programaticaly to true
self.contentView.isUserInteractionEnabled = true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With