UICollectionView only didSelectItemAtIndexPath call if user double responders will not call when user taps

I have a UICollectionView whose size depends on the size of the screen. The displayed UICollectionViewCells is the same size as the collectionView. Each cell has a UIImage, which is the size of the cell. Paging is included in CollectionView, so it’s essentially a full-screen photo slide show that the user can carry.

The problem is that -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath is called only if the user taps the cell with two fingers or long presses with one finger and then releases. It seems that by default there is no one-click selection. I did not make any changes to the CollectionView gesture recognizer, so I had problems finding a solution to this problem.

+45
ios objective-c ipad uicollectionview uicollectionviewcell
May 08 '13 at 15:34
source share
10 answers

Are you sure you do not accidentally override - (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath ? "Select" vs. "deselect" in the past worked with the completion of Xcode.

+191
May 15, '13 at 16:20
source share

I had the same problem and it turned out that the UIView containing the UICollectionView had a UITapGestureRecognizer and it was responding instead.

This explains why didSelectItemAtIndexPath only works if the user clicks with two fingers or long clicks with one finger because it does not call UITapGestureRecognizer .

So check out all the UITapGestureRecognizer that you got there, but not necessarily on the UICollectionView , but it can be on any UIView containing it.

+109
Jul 31 '13 at 10:24
source share

If you have a cell view that prevents the content of the cells from being resolved, then you cannot connect to the delegate callback for the cell.

You want to disable user interaction with the obstructive representation in either the NIB or the code.

view.userInteractionEnabled = NO;

+10
Apr 29 '15 at 16:00
source share

Just add to the already resolved question another situation in which the binding gesture may not work, as this continued to torment me.

If you return false within UICollectionViewDelegate' collectionView:shouldHighlightItemAtIndexPath: selection gesture will not function, and collectionView:didSelectItemAtIndexPath: will not be called. The default value of this delegate method is true , so you will not have a problem if you do not implement it intentionally.

+4
Aug 01 '15 at 17:03
source share

I myself ran into this problem. I initially had buttons and shortcuts, then I reorganized my user interface and turned these buttons / labels into cells for a UICollectionView .

In the end, I realized that the buttons consume my taps. I thoughtlessly moved my original buttons to the camera and did not turn it into a direct UIImage . I destroyed the actions associated with the buttons and just looked for a selection of cells, so I took the time to figure it out.

Stupid and obvious in retrospect, but it took me a couple of hours to figure out what I did.

+3
Apr 16 '15 at 12:32
source share

I had the same problem ... I was the main Began touch in the CollectionCell view, and this made didSelectItemAtIndexPath not working when I touched the cell. Override removed and everything worked.

+2
Nov 14 '13 at 16:49
source share

I ran into this problem in Swift 3 and xcode 8, I had a view and a collection view inside of this. The collection view has userInteractionEnabled for true, but it still doesn't work. This problem is fixed by overriding ifHighlightItemAt, I do not have any additional / custom implementation in this method, so I did not redefine this method. After adding the code below, the didSelectItem method is called.

 func collectionView(_ collectionView: UICollectionView, shouldHighlightItemAt indexPath: IndexPath) -> Bool { return true } 
+1
Nov 03 '16 at 22:04
source share

If you use only didselect:

 self.collectionView.allowsMultipleSelection = false 

Or delete this line.

+1
Dec 14 '16 at 8:18
source share

I happened to stumble upon this problem, and it upset me one long day until I found it. You just need to uncheck the "Enable user" box when I selected a cell in the upper left corner of the CollectionView collection in the Storyboard. and the problem is solved

+1
Apr 25 '17 at 2:53 on
source share

Remember to add UICollectionViewDataSource, UICollectionViewDelegate to the class

-one
Sep 21 '17 at 12:00
source share



All Articles