DJCollectionViewVM 是 UICollectionView 的轻量级 ViewModel 实现。
在 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];
}
关键类 | |
---|---|
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. |
##UITableView
UITableView的ViewModel:DJTableViewVM
杜克
DJCollectionViewVM遵循MIT许可证。