diff --git a/DRCollectionViewTableLayout/DRCollectionViewTableLayoutManager.h b/DRCollectionViewTableLayout/DRCollectionViewTableLayoutManager.h index e54d10b..3859ec4 100644 --- a/DRCollectionViewTableLayout/DRCollectionViewTableLayoutManager.h +++ b/DRCollectionViewTableLayout/DRCollectionViewTableLayoutManager.h @@ -199,6 +199,36 @@ column:(NSUInteger)column indexPath:(NSIndexPath *)indexPath; +/** + * Will be called when user deselects cell + * + * @param manager Collection View Table Layout Manager + * @param collectionView Collection View + * @param row Layout's row + * @param column Layout's column + * @param indexPath Collection View Cell index path + */ +- (void)collectionViewTableLayoutManager:(DRCollectionViewTableLayoutManager *)manager + collectionView:(UICollectionView *)collectionView + didDeselectCellAtRow:(NSUInteger)row + column:(NSUInteger)column + indexPath:(NSIndexPath *)indexPath; + +/** + * Will be called in order to decide if the cell has to be selected or not + * + * @param manager Collection View Table Layout Manager + * @param collectionView Collection View + * @param row Layout's row + * @param column Layout's column + * @param indexPath Collection View Cell index path + */ +- (BOOL)collectionViewTableLayoutManager:(DRCollectionViewTableLayoutManager *)manager + collectionView:(UICollectionView *)collectionView + shouldSelectItemAtRow:(NSUInteger)row + column:(NSUInteger)column + indexPath:(NSIndexPath *)indexPath; + @end /** diff --git a/DRCollectionViewTableLayout/DRCollectionViewTableLayoutManager.m b/DRCollectionViewTableLayout/DRCollectionViewTableLayoutManager.m index bcc6fb5..e1c57ff 100644 --- a/DRCollectionViewTableLayout/DRCollectionViewTableLayoutManager.m +++ b/DRCollectionViewTableLayout/DRCollectionViewTableLayoutManager.m @@ -189,4 +189,39 @@ - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPa } } + +- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath { + NSUInteger row = [(DRCollectionViewTableLayout *)collectionView.collectionViewLayout rowNumberForIndexPath:indexPath]; + NSUInteger column = [(DRCollectionViewTableLayout *)collectionView.collectionViewLayout columnNumberForIndexPath:indexPath]; + + SEL selector = @selector(collectionViewTableLayoutManager:collectionView:didDeselectCellAtRow:column:indexPath:); + + if ([self.delegate respondsToSelector:selector]) { + + [self.delegate collectionViewTableLayoutManager:self + collectionView:collectionView + didDeselectCellAtRow:row + column:column + indexPath:indexPath]; + } +} + +- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath { + NSUInteger row = [(DRCollectionViewTableLayout *)collectionView.collectionViewLayout rowNumberForIndexPath:indexPath]; + NSUInteger column = [(DRCollectionViewTableLayout *)collectionView.collectionViewLayout columnNumberForIndexPath:indexPath]; + + SEL selector = @selector(collectionViewTableLayoutManager:collectionView:shouldSelectItemAtRow:column:indexPath:); + + if ([self.delegate respondsToSelector:selector]) { + + return [self.delegate collectionViewTableLayoutManager:self + collectionView:collectionView + shouldSelectItemAtRow:row + column:column + indexPath:indexPath]; + } + + return YES; +} + @end