Created
February 20, 2018 06:36
-
-
Save yanhsiah/c7760626c04e2a321c3e9361ebca00f7 to your computer and use it in GitHub Desktop.
collectionview update
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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