Skip to content

Commit 789d9a2

Browse files
author
Zach Drayer
committed
Don't require the delegate to implement collectionView:itemAtIndexPath:willMoveToIndexPath:
1 parent 96571cb commit 789d9a2

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@
2020

2121
@protocol LXReorderableCollectionViewDataSource <UICollectionViewDataSource>
2222

23-
- (void)collectionView:(UICollectionView *)collectionView itemAtIndexPath:(NSIndexPath *)fromIndexPath willMoveToIndexPath:(NSIndexPath *)toIndexPath;
24-
2523
@optional
2624

25+
- (void)collectionView:(UICollectionView *)collectionView itemAtIndexPath:(NSIndexPath *)fromIndexPath willMoveToIndexPath:(NSIndexPath *)toIndexPath;
2726
- (BOOL)collectionView:(UICollectionView *)collectionView canMoveItemAtIndexPath:(NSIndexPath *)indexPath;
2827
- (BOOL)collectionView:(UICollectionView *)collectionView itemAtIndexPath:(NSIndexPath *)fromIndexPath canMoveToIndexPath:(NSIndexPath *)toIndexPath;
2928

LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,10 @@ - (void)invalidateLayoutIfNecessary {
154154

155155
self.selectedItemIndexPath = newIndexPath;
156156

157-
[self.dataSource collectionView:self.collectionView itemAtIndexPath:previousIndexPath willMoveToIndexPath:newIndexPath];
158-
157+
if ([self.dataSource respondsToSelector:@selector(collectionView:itemAtIndexPath:willMoveToIndexPath:)]) {
158+
[self.dataSource collectionView:self.collectionView itemAtIndexPath:previousIndexPath willMoveToIndexPath:newIndexPath];
159+
}
160+
159161
__weak typeof(self) weakSelf = self;
160162
[self.collectionView performBatchUpdates:^{
161163
__strong typeof(self) strongSelf = weakSelf;

0 commit comments

Comments
 (0)