@@ -545,7 +545,7 @@ - (void)cellTouchCancelled {
545545
546546- (void )userSelectedItemAtIndexPath : (NSIndexPath *)indexPath {
547547 if (self.allowsMultipleSelection && [_indexPathsForSelectedItems containsObject: indexPath]) {
548- [self deselectItemAtIndexPath: indexPath animated: YES ];
548+ [self deselectItemAtIndexPath: indexPath animated: YES notifyDelegate: YES ];
549549 }
550550 else {
551551 [self selectItemAtIndexPath: indexPath animated: YES scrollPosition: PSTCollectionViewScrollPositionNone notifyDelegate: YES ];
@@ -556,14 +556,16 @@ - (void)userSelectedItemAtIndexPath:(NSIndexPath *)indexPath {
556556- (void )selectItemAtIndexPath : (NSIndexPath *)indexPath animated : (BOOL )animated scrollPosition : (PSTCollectionViewScrollPosition)scrollPosition notifyDelegate : (BOOL )notifyDelegate {
557557
558558 BOOL shouldSelect = YES ;
559- if (_collectionViewFlags.delegateShouldSelectItemAtIndexPath ) {
559+ if (notifyDelegate && _collectionViewFlags.delegateShouldSelectItemAtIndexPath ) {
560560 shouldSelect = [self .delegate collectionView: self shouldSelectItemAtIndexPath: indexPath];
561561 }
562562
563563 if (shouldSelect) {
564564 if (!self.allowsMultipleSelection ) {
565565 for (NSIndexPath *selectedIndexPath in [_indexPathsForSelectedItems copy ]) {
566- [self deselectItemAtIndexPath: selectedIndexPath animated: animated];
566+ if (![indexPath isEqual: selectedIndexPath]) {
567+ [self deselectItemAtIndexPath: selectedIndexPath animated: animated notifyDelegate: notifyDelegate];
568+ }
567569 }
568570 }
569571 if (self.allowsSelection ) {
@@ -582,22 +584,31 @@ - (void)selectItemAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated s
582584}
583585
584586- (void )selectItemAtIndexPath : (NSIndexPath *)indexPath animated : (BOOL )animated scrollPosition : (PSTCollectionViewScrollPosition)scrollPosition {
585- [self selectItemAtIndexPath: indexPath animated: animated scrollPosition: scrollPosition notifyDelegate: YES ];
587+ [self selectItemAtIndexPath: indexPath animated: animated scrollPosition: scrollPosition notifyDelegate: NO ];
588+ }
589+
590+ - (void )deselectItemAtIndexPath : (NSIndexPath *)indexPath animated : (BOOL )animated
591+ {
592+ [self deselectItemAtIndexPath: indexPath animated: animated notifyDelegate: NO ];
586593}
587594
588- - (void )deselectItemAtIndexPath : (NSIndexPath *)indexPath animated : (BOOL )animated {
595+ - (void )deselectItemAtIndexPath : (NSIndexPath *)indexPath animated : (BOOL )animated notifyDelegate : ( BOOL ) notify {
589596 if ([_indexPathsForSelectedItems containsObject: indexPath]) {
590597 PSTCollectionViewCell *selectedCell = [self cellForItemAtIndexPath: indexPath];
591598 selectedCell.selected = NO ;
592599 [_indexPathsForSelectedItems removeObject: indexPath];
593600
594- [self unhighlightItemAtIndexPath: indexPath animated: animated notifyDelegate: YES ];
601+ [self unhighlightItemAtIndexPath: indexPath animated: animated notifyDelegate: notify];
602+
603+ if (notify && _collectionViewFlags.delegateDidDeselectItemAtIndexPath ) {
604+ [self .delegate collectionView: self didDeselectItemAtIndexPath: indexPath];
605+ }
595606 }
596607}
597608
598609- (BOOL )highlightItemAtIndexPath : (NSIndexPath *)indexPath animated : (BOOL )animated scrollPosition : (PSTCollectionViewScrollPosition)scrollPosition notifyDelegate : (BOOL )notifyDelegate {
599610 BOOL shouldHighlight = YES ;
600- if (_collectionViewFlags.delegateShouldHighlightItemAtIndexPath ) {
611+ if (notifyDelegate && _collectionViewFlags.delegateShouldHighlightItemAtIndexPath ) {
601612 shouldHighlight = [self .delegate collectionView: self shouldHighlightItemAtIndexPath: indexPath];
602613 }
603614
0 commit comments