Skip to content

Commit

Permalink
Merge pull request MortimerGoro#336 from cokodude/master
Browse files Browse the repository at this point in the history
Fix iOS 13 crash when reselecting a cell that's being removed (Issue MortimerGoro#334)
  • Loading branch information
MortimerGoro authored Aug 25, 2019
2 parents eeb3575 + 2e8b06b commit 536bea1
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions MGSwipeTableCell/MGSwipeTableCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ -(void) awakeFromNib

-(void) dealloc
{
[self hideSwipeOverlayIfNeeded];
[self hideSwipeOverlayIfNeededIncludingReselect:false];
}

-(void) initViews: (BOOL) cleanButtons
Expand Down Expand Up @@ -904,7 +904,7 @@ - (void) showSwipeOverlayIfNeeded
[self addGestureRecognizer:_tapRecognizer];
}

-(void) hideSwipeOverlayIfNeeded
-(void) hideSwipeOverlayIfNeededIncludingReselect: (BOOL) reselectCellIfNeeded
{
if (!_overlayEnabled) {
return;
Expand All @@ -921,12 +921,14 @@ -(void) hideSwipeOverlayIfNeeded
[_tableInputOverlay removeFromSuperview];
_tableInputOverlay = nil;
}

self.selectionStyle = _previusSelectionStyle;
NSArray * selectedRows = self.parentTable.indexPathsForSelectedRows;
if ([selectedRows containsObject:[self.parentTable indexPathForCell:self]]) {
self.selected = NO; //Hack: in some iOS versions setting the selected property to YES own isn't enough to force the cell to redraw the chosen selectionStyle
self.selected = YES;

if (reselectCellIfNeeded) {
self.selectionStyle = _previusSelectionStyle;
NSArray * selectedRows = self.parentTable.indexPathsForSelectedRows;
if ([selectedRows containsObject:[self.parentTable indexPathForCell:self]]) {
self.selected = NO; //Hack: in some iOS versions setting the selected property to YES own isn't enough to force the cell to redraw the chosen selectionStyle
self.selected = YES;
}
}
[self setAccesoryViewsHidden:NO];

Expand Down Expand Up @@ -973,7 +975,7 @@ -(void) refreshButtons: (BOOL) usingDelegate
-(void) willMoveToSuperview:(UIView *)newSuperview;
{
if (newSuperview == nil) { //remove the table overlay when a cell is removed from the table
[self hideSwipeOverlayIfNeeded];
[self hideSwipeOverlayIfNeededIncludingReselect:false];
}
}

Expand Down Expand Up @@ -1126,7 +1128,7 @@ - (void)setSwipeOffset:(CGFloat) newOffset;
[_leftView endExpansionAnimated:NO];
if (_rightView)
[_rightView endExpansionAnimated:NO];
[self hideSwipeOverlayIfNeeded];
[self hideSwipeOverlayIfNeededIncludingReselect:true];
_targetOffset = 0;
[self updateState:MGSwipeStateNone];
return;
Expand Down

0 comments on commit 536bea1

Please sign in to comment.