Skip to content

Commit 826e79f

Browse files
committed
Use theStrongSelf in case self has been deallocated before the completion block gets called (usually with multiple touches).
1 parent f8799c9 commit 826e79f

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

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)