Skip to content

Instantly share code, notes, and snippets.

@yanhsiah
Created February 20, 2018 06:36
Show Gist options
  • Save yanhsiah/c7760626c04e2a321c3e9361ebca00f7 to your computer and use it in GitHub Desktop.
Save yanhsiah/c7760626c04e2a321c3e9361ebca00f7 to your computer and use it in GitHub Desktop.
collectionview update
- (NSArray<NSIndexPath *> *)indexPathsFromItems:(NSArray *)items section:(NSUInteger)section
{
NSMutableArray *indexPaths = [NSMutableArray arrayWithCapacity:items.count];
[items enumerateObjectsUsingBlock:^(id tag, NSUInteger idx, BOOL *stop) {
[indexPaths addObject:[NSIndexPath indexPathForItem:idx inSection:section]];
}];
return indexPaths;
}
[self.collectionView performBatchUpdates:^{
@strongify(self);
[self.collectionView deleteItemsAtIndexPaths:[self indexPathsFromItems:self.tagItemList section:0]];
self.tagItemList = hashTags;
[self.collectionView insertItemsAtIndexPaths:[self indexPathsFromItems:self.tagItemList section:0]];
} completion:^(BOOL finished) {
@strongify(self);
[self updateWithDataSourceItems:@[baseArticle] completion:nil];
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment