测试已测试 | ✓ |
语言语言 | Obj-CObjective C |
许可证 | MIT |
发布上次发布 | 2017年3月 |
由Rafael Lopez Diez和Viacheslav Radchenko维护。
BMACollectionBatchUpdates
是一组类,用于生成对 UICollectionView
和 UITableView
的更新和扩展,以便它们可以批量安全地执行。
为了生成这些更新,必须使集合项和分区分别符合 BMAUpdatableCollectionItem
和 BMAUpdatableCollectionItem
协议。
@interface BMAExampleItemsSection : NSObject <BMAUpdatableCollectionSection>
@end
@interface BMAExampleItem : NSObject <BMAUpdatableCollectionItem>
@end
一旦有了旧数据和新的数据模型,就必须计算变更并应用它们。
@implementation BMAExampleCollectionViewController
- (void)setSections:(NSArray *)sections {
[BMACollectionUpdate calculateUpdatesForOldModel:self.sections
newModel:sections
sectionsPriorityOrder:nil
eliminatesDuplicates:YES
completion:^(NSArray *sections, NSArray *updates) {
[self.collectionView bma_performBatchUpdates:updates applyChangesToModelBlock:^{
_sections = sections;
} reloadCellBlock:^(UICollectionViewCell *cell, NSIndexPath *indexPath) {
[self reloadCell:cell atIndexPath:indexPath];
} completionBlock:nil];
}];
}
@end
@implementation BMAExampleTableViewController
- (void)setSections:(NSArray *)sections {
[BMACollectionUpdate calculateUpdatesForOldModel:self.sections
newModel:sections
sectionsPriorityOrder:nil
eliminatesDuplicates:YES
completion:^(NSArray *sections, NSArray *updates) {
[self.collectionView bma_performBatchUpdates:updates applyChangesToModelBlock:^{
_sections = sections;
} reloadCellBlock:^(UITableViewCell *cell, NSIndexPath *indexPath) {
[self reloadCell:cell atIndexPath:indexPath];
} completionBlock:nil];
}];
}
@end
BMACollectionBatchUpdates
目录下的所有文件添加到您的项目中。源代码在 MIT 许可证下分发。