diff --git a/Classes/UITableView+FDTemplateLayoutCell.h b/Classes/UITableView+FDTemplateLayoutCell.h index c82dd1c..e3bd821 100644 --- a/Classes/UITableView+FDTemplateLayoutCell.h +++ b/Classes/UITableView+FDTemplateLayoutCell.h @@ -59,6 +59,11 @@ /// @property (nonatomic, assign) BOOL fd_debugLogEnabled; +/** + * Use this if you don't want to remove cache when reload tableView + */ +- (void)fd_reloadData:(BOOL)shouldRemoveCache; + @end @interface UITableViewCell (FDTemplateLayoutCell) diff --git a/Classes/UITableView+FDTemplateLayoutCell.m b/Classes/UITableView+FDTemplateLayoutCell.m index 0a96c64..1191af2 100644 --- a/Classes/UITableView+FDTemplateLayoutCell.m +++ b/Classes/UITableView+FDTemplateLayoutCell.m @@ -277,6 +277,15 @@ - (NSArray *)fd_allIndexPathsToBePrecached @implementation UITableView (FDTemplateLayoutCellAutomaticallyCacheInvalidation) +- (void)fd_reloadData:(BOOL)shouldRemoveCache +{ + if (self.fd_autoCacheInvalidationEnabled && shouldRemoveCache) { + [self.fd_cellHeightCache.sections removeAllObjects]; + } + [self fd_reloadData]; // Primary call + [self fd_precacheIfNeeded]; +} + + (void)load { // All methods that trigger height cache's invalidation @@ -305,11 +314,7 @@ + (void)load - (void)fd_reloadData { - if (self.fd_autoCacheInvalidationEnabled) { - [self.fd_cellHeightCache.sections removeAllObjects]; - } - [self fd_reloadData]; // Primary call - [self fd_precacheIfNeeded]; + [self fd_reloadData:YES]; } - (void)fd_insertSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation @@ -483,10 +488,12 @@ - (CGFloat)fd_heightForCellWithIdentifier:(NSString *)identifier configuration:( attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:contentViewWidth]; - [cell.contentView addConstraint:tempWidthConstraint]; - // Auto layout engine does its math - fittingSize = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize]; - [cell.contentView removeConstraint:tempWidthConstraint]; + @synchronized(cell.contentView) { + [cell.contentView addConstraint:tempWidthConstraint]; + // Auto layout engine does its math + fittingSize = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize]; + [cell.contentView removeConstraint:tempWidthConstraint]; + } } else {