Uicollectionview Only Calling Didselectitematindexpath If User Double Taps, Will Not Call When User Single Taps

UICollectionView only calling didSelectItemAtIndexPath if user double taps, will not call when user single taps

Are you sure you're not accidentally overriding - (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath? "Select" vs. "deselect" has tripped me up in the past with Xcode's code completion.

UICollectionView didSelectItemAtIndexPath not called when tapped on UITextView

I would suggest to use UIGestureRecognizer for each cell and when it taped to send it to UITextView or whatever , perhaps there maybe a better solutions , but I would use this 1 because of simplicity reasons.

UICollectionView's didSelectItemAtIndexPath only called when selecting cell with two fingers

The solution: The collection view was added on top of a view containing a single-tap gesture recogniser. This some how caused this behaviour. I removed the recogniser from the collection views parent view and it works.

Feel free to explain why this is expected behaviour. I would have argued that the top most view (CollectionView) handles the touches before they are passed to the view behind.

didSelectItemAtIndexPath Doesn't Work In Collection View Swift

as @santhu said (https://stackoverflow.com/a/21970378/846780)

didSelectItemAtIndexPath is called when none of the subView of
collectionViewCell respond to that touch. As the textView respond to
those touches, so it won't forward those touches to its superView, so
collectionView won't get it.

So, you have a UILongPressGestureRecognizer and it avoid didSelectItemAtIndexPath call.

With UILongPressGestureRecognizer approach you need to handle handleLongPress delegate method. Basically you need to get gestureReconizer.locationInView and know the indexPath located at this point (gestureReconizer.locationInView).

    func handleLongPress(gestureReconizer: UILongPressGestureRecognizer) {
if gestureReconizer.state != UIGestureRecognizerState.Ended {
return
}

let p = gestureReconizer.locationInView(self.collectionView)
let indexPath = self.collectionView.indexPathForItemAtPoint(p)

if let index = indexPath {
var cell = self.collectionView.cellForItemAtIndexPath(index)
// do stuff with your cell, for example print the indexPath
println(index.row)
} else {
println("Could not find index path")
}
}

UICollectionview: didSelectItemAtIndexPath does not work with single tap. Works with two fingers and swipe only

Duh. I've just found the issue:

There was this gestureRecognizer attached to the view, which was trapping the single tap event. I attached it to the required object and it all worked!

self.view.addGestureRecognizer(UITapGestureRecognizer(target: SearchBar, action: "resignFirstResponder"))

UICollectionViewCells and Buttons

You're doing the right think using the delegation pattern. The ultimate responsible object for any action of your views is the viewController who's displaying those views. Therefore, using it as the delegate for you cell's protocol is just right.



Related Topics



Leave a reply



Submit