1010
1111#import " ASAssert.h"
1212#import " ASMultidimensionalArrayUtils.h"
13- #import " ASDisplayNode .h"
13+ #import " ASCellNode .h"
1414#import " ASDisplayNodeInternal.h"
1515#import " ASDataController+Subclasses.h"
1616
@@ -142,7 +142,9 @@ - (void)willReloadSections:(NSIndexSet *)sections
142142 NSArray *indexPaths = ASIndexPathsForMultidimensionalArrayAtIndexSet ([self editingNodesOfKind: kind], sections);
143143 [self deleteNodesOfKind: kind atIndexPaths: indexPaths completion: nil ];
144144 // reinsert the elements
145- [self batchLayoutNodes: nodes ofKind: kind atIndexPaths: _pendingIndexPaths[kind] completion: nil ];
145+ [self batchLayoutNodes: nodes ofKind: kind atIndexPaths: _pendingIndexPaths[kind] completion: ^(NSArray *nodes, NSArray *indexPaths) {
146+ [self insertNodes: nodes ofKind: kind atIndexPaths: indexPaths completion: nil ];
147+ }];
146148 [_pendingNodes removeObjectForKey: kind];
147149 [_pendingIndexPaths removeObjectForKey: kind];
148150 }];
@@ -187,7 +189,8 @@ - (void)_populateSupplementaryNodesOfKind:(NSString *)kind withSections:(NSIndex
187189 for (NSUInteger i = 0 ; i < rowNum; i++) {
188190 NSIndexPath *indexPath = [sectionIndex indexPathByAddingIndex: i];
189191 [indexPaths addObject: indexPath];
190- [nodes addObject: [self .collectionDataSource dataController: self supplementaryNodeOfKind: kind atIndexPath: indexPath]];
192+ ASCellNode *supplementaryNode = [self .collectionDataSource dataController: self supplementaryNodeOfKind: kind atIndexPath: indexPath];
193+ [nodes addObject: supplementaryNode];
191194 }
192195 }];
193196}
@@ -208,7 +211,17 @@ - (ASSizeRange)constrainedSizeForNodeOfKind:(NSString *)kind atIndexPath:(NSInde
208211- (ASCellNode *)supplementaryNodeOfKind : (NSString *)kind atIndexPath : (NSIndexPath *)indexPath
209212{
210213 ASDisplayNodeAssertMainThread ();
211- return [self completedNodesOfKind: kind][indexPath.section][indexPath.item];
214+ NSArray *nodesOfKind = [self completedNodesOfKind: kind];
215+ NSInteger section = indexPath.section ;
216+ if (section < nodesOfKind.count ) {
217+ NSArray *nodesOfKindInSection = nodesOfKind[section];
218+ NSInteger itemIndex = indexPath.item ;
219+ if (itemIndex < nodesOfKindInSection.count ) {
220+ return nodesOfKindInSection[itemIndex];
221+ }
222+ }
223+ ASDisplayNodeAssert (NO , @" Supplementary node should exist. Kind = %@ , indexPath = %@ , collectionDataSource = %@ " , kind, indexPath, self.collectionDataSource );
224+ return [[ASCellNode alloc ] init ];
212225}
213226
214227#pragma mark - Private Helpers
0 commit comments