From 9531fbffc0c1a0403038a65bb6f97312ddf538d6 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Thu, 15 Jul 2021 17:36:46 +0800 Subject: [PATCH] iOS:flowlayout fix reused problem --- doric-iOS/Pod/Classes/Shader/DoricFlowLayoutNode.m | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/doric-iOS/Pod/Classes/Shader/DoricFlowLayoutNode.m b/doric-iOS/Pod/Classes/Shader/DoricFlowLayoutNode.m index d7907457..cd2f6b71 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricFlowLayoutNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricFlowLayoutNode.m @@ -191,7 +191,6 @@ - (UICollectionView *)build { it.dataSource = self; it.showsVerticalScrollIndicator = NO; it.showsHorizontalScrollIndicator = NO; - [it registerClass:[DoricFlowLayoutViewCell class] forCellWithReuseIdentifier:@"doricCell"]; if (@available(iOS 11, *)) { it.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; } @@ -335,8 +334,13 @@ - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collection NSUInteger position = (NSUInteger) indexPath.row; NSDictionary *model = [self itemModelAt:position]; NSDictionary *props = model[@"props"]; - - DoricFlowLayoutViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"doricCell" forIndexPath:indexPath]; + NSString *identifier = props[@"identifier"] ?: @"doricCell"; + if (position >= self.itemCount && self.onLoadMoreFuncId) { + identifier = @"doricLoadMoreCell"; + [self callLoadMore]; + } + [collectionView registerClass:[DoricFlowLayoutViewCell class] forCellWithReuseIdentifier:identifier]; + DoricFlowLayoutViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath]; if (!cell.viewNode) { DoricFlowLayoutItemNode *itemNode = [[DoricFlowLayoutItemNode alloc] initWithContext:self.doricContext]; [itemNode initWithSuperNode:self]; @@ -352,10 +356,6 @@ - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collection } else { node.view.width = (collectionView.width - (self.columnCount - 1) * self.columnSpace) / self.columnCount; } - - if (position >= self.itemCount && self.onLoadMoreFuncId) { - [self callLoadMore]; - } [node.view.doricLayout apply]; [node requestLayout]; [self callItem:position size:node.view.frame.size];