BMACollectionBatchUpdates 1.1.2

BMACollectionBatchUpdates 1.1.2

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布上次发布2017年3月

Rafael Lopez DiezViacheslav Radchenko维护。



  • Vladimir Magaziy

BMACollectionBatchUpdates 是一组类,用于生成对 UICollectionViewUITableView 的更新和扩展,以便它们可以批量安全地执行。

使用方法

为了生成这些更新,必须使集合项和分区分别符合 BMAUpdatableCollectionItemBMAUpdatableCollectionItem 协议。

@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

安装方法

手动安装

  1. 克隆、添加为子模块或下载。
  2. BMACollectionBatchUpdates 目录下的所有文件添加到您的项目中。
  3. 确保您的项目配置为使用 ARC。

许可证

源代码在 MIT 许可证下分发。

博客

在我们的技术博客上了解更多,或探索我们的其他开源项目