@@ -404,6 +404,51 @@ - (void)reloadDataWithAnimationOptions:(ASDataControllerAnimationOptions)animati
404404 }];
405405}
406406
407+ - (void )reloadDataAndWait
408+ {
409+ [self performEditCommandWithBlock: ^{
410+ ASDisplayNodeAssertMainThread ();
411+ [_editingTransactionQueue waitUntilAllOperationsAreFinished ];
412+
413+ [self accessDataSourceSynchronously: YES withBlock: ^{
414+ NSUInteger sectionCount = [_dataSource numberOfSectionsInDataController: self ];
415+ NSMutableArray *updatedNodes = [NSMutableArray array ];
416+ NSMutableArray *updatedIndexPaths = [NSMutableArray array ];
417+ [self _populateFromEntireDataSourceWithMutableNodes: updatedNodes mutableIndexPaths: updatedIndexPaths];
418+
419+ // Measure nodes whose views are loaded before we leave the main thread
420+ [self layoutLoadedNodes: updatedNodes ofKind: ASDataControllerRowNodeKind atIndexPaths: updatedIndexPaths];
421+
422+ // Allow subclasses to perform setup before going into the edit transaction
423+ [self prepareForReloadData ];
424+
425+ LOG (@" Edit Transaction - reloadData" );
426+
427+ ASDataControllerAnimationOptions animationOptions = UITableViewRowAnimationNone;
428+
429+ // Remove everything that existed before the reload, now that we're ready to insert replacements
430+ NSArray *indexPaths = ASIndexPathsForMultidimensionalArray (_editingNodes[ASDataControllerRowNodeKind]);
431+ [self _deleteNodesAtIndexPaths: indexPaths withAnimationOptions: animationOptions];
432+
433+ NSMutableArray *editingNodes = _editingNodes[ASDataControllerRowNodeKind];
434+ NSMutableIndexSet *indexSet = [[NSMutableIndexSet alloc ] initWithIndexesInRange: NSMakeRange (0 , editingNodes.count)];
435+ [self _deleteSectionsAtIndexSet: indexSet withAnimationOptions: animationOptions];
436+
437+ [self willReloadData ];
438+
439+ // Insert each section
440+ NSMutableArray *sections = [NSMutableArray arrayWithCapacity: sectionCount];
441+ for (int i = 0 ; i < sectionCount; i++) {
442+ [sections addObject: [[NSMutableArray alloc ] init ]];
443+ }
444+
445+ [self _insertSections: sections atIndexSet: [NSIndexSet indexSetWithIndexesInRange: NSMakeRange (0 , sectionCount)] withAnimationOptions: animationOptions];
446+
447+ [self _batchLayoutNodes: updatedNodes atIndexPaths: updatedIndexPaths withAnimationOptions: animationOptions];
448+ }];
449+ }];
450+ }
451+
407452#pragma mark - Data Source Access (Calling _dataSource)
408453
409454/* *
@@ -413,7 +458,12 @@ - (void)reloadDataWithAnimationOptions:(ASDataControllerAnimationOptions)animati
413458 */
414459- (void )accessDataSourceWithBlock : (dispatch_block_t )block
415460{
416- if (_asyncDataFetchingEnabled) {
461+ [self accessDataSourceSynchronously: NO withBlock: block];
462+ }
463+
464+ - (void )accessDataSourceSynchronously : (BOOL )synchronously withBlock : (dispatch_block_t )block
465+ {
466+ if (!synchronously && _asyncDataFetchingEnabled) {
417467 [_dataSource dataControllerLockDataSource ];
418468 dispatch_async (dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_HIGH, 0 ), ^{
419469 block ();
0 commit comments