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
The Paper Folding/Unfolding Effect in Twitter for iPad
What Is Nsmanagedobjectcontext's Performblock: Used For
Iphone: Can a Dev Other Than Team Agent Build an App for Distribution
Get Uiscrollview to Scroll to the Top
"Rctbundleurlprovider.H" File Not Found - Appdelegate.M
Sending Push Notifications to iOS from Pwa
How to Change "Initwithnibname" in Storyboard
How to Get Distance of Object from iPhone Camera Using Image Exif Meta Data
iOS 8 - Screen Blank After Dismissing View Controller with Custom Presentation
How to Set a Custom View's Intrinsic Content Size in Swift
Change the Font of a Uibarbuttonitem
Width and Height Equal to Its Superview Using Autolayout Programmatically
How to Change Height of Grouped Uitableview Header
Differencebetween the App Id and the Bundle Id? Where Is the App Id in the Xcode Project
Frosted Glass (iOS 7 Blur) Effect
How to Make a Swiftui Gesture That Keeps Running Code While the View Is Pressed
Swift 3 How to Get Date for Tomorrow and Yesterday ( Take Care Special Case ) New Month or New Year