AsyncDisplayKit icon indicating copy to clipboard operation
AsyncDisplayKit copied to clipboard

[ASCommonCollectionViewDelegate] -collectionView:didDeselectItemAtIndexPath not called

Open tomizimobile opened this issue 11 years ago • 2 comments

I have a ASCollectionView with allowsMultipleSelection set to true. Multiple selection works fine, but neither -collectionView:shouldDeselectItemAtIndexPath nor -collectionView:didDeselectItemAtIndexPath seem to be called when trying to deselect an item. A quick change to the sample project "ASCollectionView" in ViewController.m with the following shows this behavior:

- (instancetype)init
{
  ...
  _collectionView.allowsMultipleSelection = YES;
  ...
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
  [_collectionView nodeForItemAtIndexPath:indexPath].backgroundColor = [UIColor greenColor];
}

- (BOOL)collectionView:(UICollectionView *)collectionView shouldDeselectItemAtIndexPath:(NSIndexPath *)indexPath
{
  return YES;
}

- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath
{
  [_collectionView nodeForItemAtIndexPath:indexPath].backgroundColor = [UIColor lightGrayColor];
}

I'm using the current master (59d52ced3fbae5fc0e6220eabd692602062bb2c1)

tomizimobile avatar Nov 18 '15 15:11 tomizimobile

@tomizimobile Thank you for the clear description of the issue, especially referencing the version you're using!

I believe this is a real bug, and before noticing this issue had just filed this one: https://github.com/facebook/AsyncDisplayKit/issues/892

@levi, @vitalybaev - your time is very valuable and I have no explicit expectation, so don't worry if you're busy. If you do have time, this is one of the most valuable areas you could help ASDK! Next time I'll move a bit more slowly before adding a feature like selection, as it surely has some more details than we first imagined :)

appleguy avatar Nov 29 '15 01:11 appleguy

I verified that this works using the collectionNode API:

- (void)viewDidLoad
{
  [super viewDidLoad];
...
self.collectionNode.allowsMultipleSelection = YES;
...
}

- (void)collectionNode:(ASCollectionNode *)collectionNode didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
  [collectionNode nodeForItemAtIndexPath:indexPath].backgroundColor = [UIColor greenColor];
}

- (BOOL)collectionNode:(ASCollectionNode *)collectionNode shouldDeselectItemAtIndexPath:(NSIndexPath *)indexPath
{
  return YES;
}

- (void)collectionNode:(ASCollectionNode *)collectionNode didDeselectItemAtIndexPath:(nonnull NSIndexPath *)indexPath
{
  [collectionNode nodeForItemAtIndexPath:indexPath].backgroundColor = [UIColor lightGrayColor];
}

hannahmbanana avatar Nov 14 '16 06:11 hannahmbanana