APLArrayDataSource 0.0.4

APLArrayDataSource 0.0.4

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最后发布2015年5月

Michael KamphausencgTino RachuiMathias KöhnkeMathias KoehnkeNico SchümannHeiko WichmannStephan LernerFamara Kassama维护。



  • Chris Eidhof、Michael Kamphausen 和 Tobias Conradi 制作

UITableViewDataSource for NSArray。一个用于在 UITableView 中显示的数据表示为 NSArray 的 UITableViewDataSource。

概念和代码来自这篇优秀的objc.io 文章

此外还支持

  • 多个单元格标识符
  • 单元格编辑(仅删除)
  • 部分,使用嵌套 NSAry 作为数据源(使用子类 APLArrayWithSectionsDataSource)

安装

使用

导入头文件

#import "ALArrayDataSource.h"

声明 dataSource 属性

@property (nonatomic, strong) ALArrayDataSource* dataSource;

使用您的数据数组(这里为空),单元格标识符,一个配置 tableView 单元格的 block 以及将 tableView dataSource 设置为 dataSource

self.dataSource = [[ALArrayDataSource alloc] initWithItems:@[] cellIdentifier:@"CellIdentifier" configureCellBlock:[self configureCell]];
self.tableView.dataSource = self.dataSource;

声明一个返回配置 tableView 单元格 block 的方法

- (TableViewCellConfigureBlock)configureCell {
    return ^(UITableViewCell* cell, id yourModel) {
        cell.textLabel.text = yourModel.name;
        cell.imageView.image = yourModel.image;
    };
}

当您获取新数据时,更新您的 dataSource 和 tableView 如此

self.dataSource.items = modelArray;
[self.tableView reloadData];