Skip to content

Commit 45f450c

Browse files
committed
Merge pull request #16 from charlietuna/master
Use theStrongSelf in case self has been deallocated before the animation completion block gets called
2 parents 1a4c12f + 826e79f commit 45f450c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

LXReorderableCollectionViewFlowLayout/LXReorderableCollectionViewFlowLayout.m

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,11 @@ - (void)handleLongPressGesture:(UILongPressGestureRecognizer *)theLongPressGestu
264264
[theStrongSelf.currentView removeFromSuperview];
265265
[theStrongSelf invalidateLayout];
266266

267-
if ([self.collectionView.delegate conformsToProtocol:@protocol(LXReorderableCollectionViewDelegateFlowLayout)]) {
268-
id<LXReorderableCollectionViewDelegateFlowLayout> theDelegate = (id<LXReorderableCollectionViewDelegateFlowLayout>)self.collectionView.delegate;
267+
// Use theStrongSelf in case self has been deallocated before the completion block gets called.
268+
if ([theStrongSelf.collectionView.delegate conformsToProtocol:@protocol(LXReorderableCollectionViewDelegateFlowLayout)]) {
269+
id<LXReorderableCollectionViewDelegateFlowLayout> theDelegate = (id<LXReorderableCollectionViewDelegateFlowLayout>)theStrongSelf.collectionView.delegate;
269270
if ([theDelegate respondsToSelector:@selector(collectionView:layout:didEndReorderingAtIndexPath:)]) {
270-
[theDelegate collectionView:self.collectionView layout:self didEndReorderingAtIndexPath:theIndexPathOfSelectedItem];
271+
[theDelegate collectionView:theStrongSelf.collectionView layout:theStrongSelf didEndReorderingAtIndexPath:theIndexPathOfSelectedItem];
271272
}
272273
}
273274
}];

0 commit comments

Comments
 (0)