Wikipedia

Search results

20 November 2013

Update UICollectionView as a batch

1) get all the data you need

2) create array of index paths

3) update your view

sample code:

NSArray* dataArray = // however you get the data
  if (dataArray.count == 0) {
    moreTaps = NO;
    return;
  }
                    
NSMutableArray* indexArray = @[].mutableCopy;
NSInteger dataSourceCount = arrayDisplay.count;

for (int i = 0; i < dataArray.count; i++) {
                        
                        
if ([indexHolderArray containsObject:[[dataArray objectAtIndex:i] anId]]) {
  continue;
}
                        
[arrayDisplay addObject:[dataArray objectAtIndex:i]];

NSInteger indexPathItem = i + dataSourceCount;
  [indexArray addObject:[NSIndexPath indexPathForRow:indexPathItem inSection:0]];                      
}
                    
dispatch_sync(dispatch_get_main_queue(), ^{
  [_collectionView insertItemsAtIndexPaths:indexArray];
});

No comments:

Post a Comment