11

I use UICollectionView to display server-related information. This UICollectionView allows cells selection to display some nested data. Unfortunately if user touches and holds any cells during my app calls [collectionView reloadData] this cell doesn't react on touches anymore (collectionView:didSelectItemAtIndexPath: method isn't called). I can select any cells except this one.

I created simple application that can reproduce this problem: link

Any ideas how to fix it?

Vitaly S.
  • 2,389
  • 26
  • 40
  • 1
    +1 for nice test code. I overrode touchesBegan and touchesEnded in the custom cell, and it's still receiving touches even though didSelectRowAtIndexPath isn't called any more. It's superview is still the collection view, and its frame is still the same. So far, I don't see reason for this behavior. – rdelmar May 29 '14 at 20:34
  • 1
    I noticed one other thing. If you give the cells a colored selectedBackgroundView, the cell you held down during the reload never appears to go back to the unselected state -- however, if you log the selected state, it shows it as not selected. I even tried explicitly setting it to NO in an override of prepareForReuse, but that didn't make any difference. Continued below. – rdelmar May 29 '14 at 21:08
  • 1
    Interestingly though, if after you make one of these non-selectable cells, if you select one of the other "normal" cells, it will appropriately show the selected background view, and when you touch the non-seelctable cell, the "normal" cell goes back to the unselected state. So, it appears that the collection view is being notified of the touch on the non-selectable cell, but not calling its didSelectItem method. Curious. – rdelmar May 29 '14 at 21:08
  • 1
    I also tried submitting the selected and highlighted states in prepareForReuse with no luck. NO IDEA why we're not getting didSelectItem =[ – rooftop May 29 '14 at 21:23

2 Answers2

18

Looks like a bug (I believe there is a similar issue where a cell.selected = YES without a -selectItemAtIndexPath:animated:scrollPosition: caused the cell to be unable to be unselected)

However if you do this:

[self.collectionView reloadItemsAtIndexPaths:[self.collectionView indexPathsForVisibleItems]];

instead of [self.collectionView reloadData] it is working as expected.

Update: Found the answer of the issue mentioned above

Another Update: It appears that this indeed was a bug. Tested the original project on the iOS8 simulator and the issue now is resolved.

Community
  • 1
  • 1
Alladinian
  • 34,483
  • 6
  • 89
  • 91
2

As per @Alladinian's answer says that instead of use of [self.collectionView reloadData], use self.collectionView reloadItemsAtIndexPaths:..... worked in your demo and also I did tried with

[self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];

Its also worked properly.

iPatel
  • 46,010
  • 16
  • 115
  • 137