From 514d7afa55dd447f6e91f5a14dd6b5adfef6588c Mon Sep 17 00:00:00 2001 From: dhcdht Date: Wed, 8 Jul 2015 18:14:48 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=94=AF=E6=8C=81reloadData=E6=97=B6?= =?UTF-8?q?=E4=B8=8D=E5=88=A0=E9=99=A4=E5=8E=9F=E6=9D=A5=E7=9A=84=E9=AB=98?= =?UTF-8?q?=E5=BA=A6=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Classes/UITableView+FDTemplateLayoutCell.h | 5 +++++ Classes/UITableView+FDTemplateLayoutCell.m | 15 ++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) 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..f0a480d 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 From 863c741f1c30f52ee90903768de89c4cb09fc72f Mon Sep 17 00:00:00 2001 From: dhcdht Date: Fri, 10 Jul 2015 13:17:20 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E9=98=BB=E6=AD=A2=E5=A4=9A=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E5=90=8C=E6=97=B6=E8=AE=BF=E9=97=AE=20systemLayoutSiz?= =?UTF-8?q?eFittingSize:=20=E6=97=B6=E7=9A=84=20crash?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Classes/UITableView+FDTemplateLayoutCell.m | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Classes/UITableView+FDTemplateLayoutCell.m b/Classes/UITableView+FDTemplateLayoutCell.m index f0a480d..1191af2 100644 --- a/Classes/UITableView+FDTemplateLayoutCell.m +++ b/Classes/UITableView+FDTemplateLayoutCell.m @@ -488,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 {