Skip to content
This repository was archived by the owner on Oct 10, 2018. It is now read-only.

Commit 956b813

Browse files
author
Joaquin Perez Lopez
committed
Added respondToSelector check in didDeselectCellAtRow and shouldSelectItemAtIndexPath since both are optionals methods
1 parent 6ed3f04 commit 956b813

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

DRCollectionViewTableLayout/DRCollectionViewTableLayoutManager.m

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,18 +194,34 @@ - (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndex
194194
NSUInteger row = [(DRCollectionViewTableLayout *)collectionView.collectionViewLayout rowNumberForIndexPath:indexPath];
195195
NSUInteger column = [(DRCollectionViewTableLayout *)collectionView.collectionViewLayout columnNumberForIndexPath:indexPath];
196196

197-
[self.delegate collectionViewTableLayoutManager:self
197+
SEL selector = @selector(collectionViewTableLayoutManager:collectionView:didDeselectCellAtRow:column:indexPath:);
198+
199+
if ([self.delegate respondsToSelector:selector]) {
200+
201+
[self.delegate collectionViewTableLayoutManager:self
198202
collectionView:collectionView
199203
didDeselectCellAtRow:row
200204
column:column
201205
indexPath:indexPath];
206+
}
202207
}
203208

204209
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {
205210
NSUInteger row = [(DRCollectionViewTableLayout *)collectionView.collectionViewLayout rowNumberForIndexPath:indexPath];
206211
NSUInteger column = [(DRCollectionViewTableLayout *)collectionView.collectionViewLayout columnNumberForIndexPath:indexPath];
207212

208-
return [self.delegate collectionViewTableLayoutManager:self collectionView:collectionView shouldSelectItemAtRow:row column:column indexPath:indexPath];
213+
SEL selector = @selector(collectionViewTableLayoutManager:collectionView:shouldSelectItemAtIndexPath:column:indexPath:);
214+
215+
if ([self.delegate respondsToSelector:selector]) {
216+
217+
return [self.delegate collectionViewTableLayoutManager:self
218+
collectionView:collectionView
219+
shouldSelectItemAtRow:row
220+
column:column
221+
indexPath:indexPath];
222+
}
223+
224+
return YES;
209225
}
210226

211227
@end

0 commit comments

Comments
 (0)