独立于项目的、基于块的、支持 UITableView、UICollectionView 和 NSFetchedResultsController 的数据源。该项目有助于使视图控制器更轻量。可以为每个分区提供一个额外的单元格标识符,并添加多个分区。这使得在单个 UITableView 中使用不同的 UITableViewCell 子类成为可能。
要运行示例项目;首先克隆仓库并从 Example 目录运行 pod install
,或者直接使用 SHDataSources.xcworkspace 文件并构建 SHDataSourceDemo 计划。
该项目支持以下类型的数据源
SHDataSource
- 不可变和可变数据源,提供添加、插入、删除和重新排序任意项目。SHEmptyDataSource
- 返回零分区、零行和零单元格。可在等待项目下载时使用。预期用法如下(请参阅仓库中包含的示例)(
@interface MyCustomClass()
[...]
@property(nonatomic, strong)SHDataSource *dataSource;
[...]
@end
SHItemCollection *collection = [[SHItemCollection alloc] initWithItems:@[[UIColor redColor], [UIColor greenColor], [UIColor blueColor]] @"CELL_ID"];
self.dataSource = [SHDataSource dataSourceWithItemCollection:collection cellConfigurationHandler:^(id <SHDataSourcesCellDataHandler> cell, id item, NSIndexPath *indexPath) {
[cell setData:item];
}];
self.dataSource.editable = YES;
self.dataSource.draggingEnabled = YES;
self.tableView.dataSource = self.dataSource;
SHDataSources 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。