项目作者: yohenpeng

项目描述 :
更好的管理TableView数据源,支持异步异步计算Cell、SectionHeader、SectionFooter高度,目前只提供Objective-C版本
高级语言: Objective-C
项目地址: git://github.com/yohenpeng/YHTableComponent.git
创建时间: 2019-05-08T06:20:16Z
项目社区:https://github.com/yohenpeng/YHTableComponent

开源协议:

下载


YHTableComponent

  • YHTableComponent优点:
  1. 更好的管理TableView数据源,特别是需要灵活配置展示项目的时候,按照以前实现协议DataSource和Delegate的时候会写很多HardCode,让人不堪其烦。在YHTableComponent中使用YHUIModel对象的数组来管理数据源,逻辑清晰。
  2. 支持异步异步计算Cell、SectionHeader、SectionFooter高度, 在传递DataModel给到YHTableSectionHeaderFooterModel、YHTableCellModel的时候,就会调用各个类实现的calculateHeight方法计算并保存高度。

Cell、SectionHeader、SectionFooter需实现以下协议

  1. @protocol YHTableViewUIDelegate <NSObject>
  2. @required
  3. //计算高度
  4. + (CGFloat)calculateHeight:(id)dataModel;
  5. @optional
  6. //填充内容
  7. - (void)fillData:(id)data;
  8. @end

ViewModel中组合数据源:

  1. - (void)fetch:(void (^)(NSError *, NSArray<YHTableUIModel *> *))completion{
  2. //...
  3. //异步请求数据
  4. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5. NSMutableArray *array = [NSMutableArray new];
  6. {//section one
  7. YHTableUIModel *uiModel = [[YHTableUIModel alloc]initWithBusinessId:kSectionOneId];
  8. YHTableCellModel *cellModel = [[YHTableCellModel alloc]initWithBusinessId:@"" cellClass:kUserInfoCell];
  9. [cellModel fillDataAndRefreshHeight:@"yohenpeng"];
  10. [uiModel.arr_cellModels addObject:cellModel];
  11. for (NSInteger i = 0; i < 10; i++) {
  12. cellModel = [[YHTableCellModel alloc]initWithBusinessId:@"" cellClass:kOrderInfoCell];
  13. [cellModel fillDataAndRefreshHeight:@"orderInfo"];
  14. [uiModel.arr_cellModels addObject:cellModel];
  15. }
  16. [array addObject:uiModel];
  17. }
  18. { //section two
  19. //section header
  20. YHTableUIModel *uiModel = [[YHTableUIModel alloc]initWithBusinessId:kSectionTwoId];
  21. uiModel.sectionHeaderModel = [[YHTableSectionHeaderFooterModel alloc]initWithBusinessId:@"" viewClass:kSectionHeaderOneView];
  22. [uiModel.sectionHeaderModel fillDataAndRefreshHeight:@"sectionHeader"];
  23. YHTableCellModel *cellModel = [[YHTableCellModel alloc]initWithBusinessId:@"" cellClass:kHealthCircleCell];
  24. [cellModel fillDataAndRefreshHeight:@"circleInfo"];
  25. [uiModel.arr_cellModels addObject:cellModel];
  26. [array addObject:uiModel];
  27. }
  28. if (completion) {
  29. dispatch_async(dispatch_get_main_queue(), ^{
  30. completion(nil,array);
  31. });
  32. }
  33. });
  34. }
  • 集成方式:

    pod ‘YHTableComponent’

  • 目前只提供Objective-C版本