DJCollectionViewVM 1.0.0

DJCollectionViewVM 1.0.0

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布最后发布2017 年 9 月

Dokay Dou 维护。



  • 作者:
  • Dokay

什么

DJCollectionViewVM 是 UICollectionView 的轻量级 ViewModel 实现。

特性

  • 使用 UICollectionView 和 UICollectionViewFlowLayout 实现线性布局,代码更少,更灵活;
  • 动态计算 cell 和 SupplementaryView 的大小;
  • 支持类似于 UITableView 的 header 和 footer;
  • 支持 iOS 7.0+ 的预加载;

要求

  • Xcode 7 或更高版本
  • Apple LLVM 编译器
  • iOS 7.0 或更高版本
  • ARC

示例

在 Xcode 中构建和运行 DJComponentCollectionViewVM.xcodeproj

快速入门

  • 示例代码
- (void)testNormal
{
    DJCollectionViewVMCellRegister(self.collectionVM, DJCollectionViewTitleCellRow, DJCollectionViewTitleCell);
    [self.collectionVM removeAllSections];
    
    DJCollectionViewVMSection *contentSection = [DJCollectionViewVMSection sectionWithHeaderHeight:10];
    contentSection.minimumLineSpacing = 10.0f;
    contentSection.minimumInteritemSpacing = 10.0f;
    [self.collectionVM addSection:contentSection];
    for (NSInteger i = 0; i < 100; i ++) {
        DJCollectionViewTitleCellRow *row = [DJCollectionViewTitleCellRow new];
        row.itemSize = CGSizeMake(100, 100);
        row.backgroundColor = [UIColor redColor];
        row.title = [NSString stringWithFormat:@"%@",@(i)];
        [row setSelectionHandler:^(DJCollectionViewVMRow *rowVM) {
            NSLog(@"tap %@",rowVM.indexPath);
        }];
        [contentSection addRow:row];
    }
    
    [self.collectionView reloadData];
}
  • API
关键类
DJCollectionViewVM UICollectionView 的 ViewModel,该类实现了 UICollectionViewDelegate,UICollectionViewDataSource 和 UICollectionViewDelegateFlowLayout。它有多个DJCollectionViewVMSection部分。,每个部分有多个DJCollectionViewVMRow
,每个部分有多个 行。DJCollectionViewVM部分中的 ViewModel,每个部分有多个DJCollectionViewVMRow行。
DJCollectionViewVMRow 部分中行的 ViewModel,它是所有DJCollectionViewVM行层次结构的根类。
您应该DJCollectionViewVMRow以获取特定于您应用程序需求的单元格特性。通过DJCollectionViewVMRow,行继承了一个基本接口,该接口与DJCollectionViewVM,每个部分有多个.
DJCollectionViewVMCell DJCollectionViewVMRow(ViewModel) 的视图,它定义了在DJCollectionViewVMSection对象中出现的单元格的属性和行为。您应该DJCollectionViewVMCell以获取特定于您应用程序需求的单元格特性和行为。默认情况下,它与DJCollectionViewVMRow.
DJCollectionViewVMReusable 部分 header 和 footer 中 supplementary view 的 ViewModel,它是所有DJCollectionViewVMsupplementary 视图层次结构的根类。
您应该DJCollectionViewVMReusable以获取特定于您应用程序需求的 supplementary 视图特性。通过DJCollectionViewVMReusable,supplementary 视图继承了一个基本接口,该接口与DJCollectionViewVM,每个部分有多个.
DJCollectionViewVMReusableView DJCollectionViewVMReusable(ViewModel) 的视图,它定义了在DJCollectionViewVMSection对象中出现的单元格的属性和行为。您应该DJCollectionViewVMReusableView中出现的 supplementary 视图的属性和行为。要获取特定于您应用程序需求的 supplementary 视图特性和行为,请DJCollectionViewVMReusable.
  • 为您项目中的现有单元格
    1. 如果您的单元格的父类是 UICollectionViewCell,那么将其更改为DJCollectionViewVMCell。
    2. 如果您的单元格的父类是您自定义的类,则需要实现协议DJCollectionViewVMCellDelegate或将它更改为DJCollectionViewVMCell。

##UITableView

UITableView的ViewModel:DJTableViewVM

联系

杜克

许可证

DJCollectionViewVM遵循MIT许可证。