From 690f90a899573ab89d8722ef86e7d40f4b4ace6c Mon Sep 17 00:00:00 2001 From: Scott Goodson Date: Sun, 27 Dec 2015 15:34:26 -0800 Subject: [PATCH] Supplementary nodes must be added to the completed nodes after their measurement completes following individual section reloads. --- .../Details/ASCollectionDataController.mm | 21 +++++++++++++++---- .../Sample/ViewController.m | 6 ++++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/AsyncDisplayKit/Details/ASCollectionDataController.mm b/AsyncDisplayKit/Details/ASCollectionDataController.mm index e8028161d6..9e51ee6a24 100644 --- a/AsyncDisplayKit/Details/ASCollectionDataController.mm +++ b/AsyncDisplayKit/Details/ASCollectionDataController.mm @@ -10,7 +10,7 @@ #import "ASAssert.h" #import "ASMultidimensionalArrayUtils.h" -#import "ASDisplayNode.h" +#import "ASCellNode.h" #import "ASDisplayNodeInternal.h" #import "ASDataController+Subclasses.h" @@ -142,7 +142,9 @@ NSArray *indexPaths = ASIndexPathsForMultidimensionalArrayAtIndexSet([self editingNodesOfKind:kind], sections); [self deleteNodesOfKind:kind atIndexPaths:indexPaths completion:nil]; // reinsert the elements - [self batchLayoutNodes:nodes ofKind:kind atIndexPaths:_pendingIndexPaths[kind] completion:nil]; + [self batchLayoutNodes:nodes ofKind:kind atIndexPaths:_pendingIndexPaths[kind] completion:^(NSArray *nodes, NSArray *indexPaths) { + [self insertNodes:nodes ofKind:kind atIndexPaths:indexPaths completion:nil]; + }]; [_pendingNodes removeObjectForKey:kind]; [_pendingIndexPaths removeObjectForKey:kind]; }]; @@ -187,7 +189,8 @@ for (NSUInteger i = 0; i < rowNum; i++) { NSIndexPath *indexPath = [sectionIndex indexPathByAddingIndex:i]; [indexPaths addObject:indexPath]; - [nodes addObject:[self.collectionDataSource dataController:self supplementaryNodeOfKind:kind atIndexPath:indexPath]]; + ASCellNode *supplementaryNode = [self.collectionDataSource dataController:self supplementaryNodeOfKind:kind atIndexPath:indexPath]; + [nodes addObject:supplementaryNode]; } }]; } @@ -208,7 +211,17 @@ - (ASCellNode *)supplementaryNodeOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath { ASDisplayNodeAssertMainThread(); - return [self completedNodesOfKind:kind][indexPath.section][indexPath.item]; + NSArray *nodesOfKind = [self completedNodesOfKind:kind]; + NSInteger section = indexPath.section; + if (section < nodesOfKind.count) { + NSArray *nodesOfKindInSection = nodesOfKind[section]; + NSInteger itemIndex = indexPath.item; + if (itemIndex < nodesOfKindInSection.count) { + return nodesOfKindInSection[itemIndex]; + } + } + ASDisplayNodeAssert(NO, @"Supplementary node should exist. Kind = %@, indexPath = %@, collectionDataSource = %@", kind, indexPath, self.collectionDataSource); + return [[ASCellNode alloc] init]; } #pragma mark - Private Helpers diff --git a/examples/CustomCollectionView/Sample/ViewController.m b/examples/CustomCollectionView/Sample/ViewController.m index b28fd7b652..3513db33df 100644 --- a/examples/CustomCollectionView/Sample/ViewController.m +++ b/examples/CustomCollectionView/Sample/ViewController.m @@ -101,11 +101,13 @@ static NSUInteger kNumberOfImages = 14; return [[SupplementaryNode alloc] initWithText:text]; } -- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { +- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView +{ return _sections.count; } -- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { +- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section +{ return [_sections[section] count]; }