Last active
August 20, 2016 11:25
-
-
Save mickeyl/7abc33f65b9fed838e9f4c3e48e9d541 to your computer and use it in GitHub Desktop.
Work around a crash in UITableView when changing layout during scrolling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void)triggerRelayoutIfNecessary | |
{ | |
[_activityIndicator stopAnimating]; | |
float newHeight = [self.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height; | |
if ( newHeight != _lastHeight ) | |
{ | |
UITableView* tv = (UITableView*)[self LT_findFirstSuperviewOfClass:UITableView.class]; | |
if ( tv.isDragging || tv.isDecelerating ) | |
{ | |
LOG( @"Can't trigger updating because tableview is being scrolled" ); | |
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ | |
[self triggerRelayoutIfNecessary]; | |
}); | |
return; | |
} | |
_lastHeight = newHeight; | |
[self setNeedsUpdateConstraints]; | |
[tv beginUpdates]; | |
[tv endUpdates]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment