测试已测试 | ✗ |
语言语言 | Obj-CObjective C |
许可证 | MIT |
发布最后发布 | 2015年5月 |
由Michael Kamphausen、cg、Tino Rachui、Mathias Köhnke、Mathias Koehnke、Nico Schümann、Heiko Wichmann、Stephan Lerner、Famara Kassama维护。
UITableViewDataSource for NSArray。一个用于在 UITableView 中显示的数据表示为 NSArray 的 UITableViewDataSource。
概念和代码来自这篇优秀的objc.io 文章。
此外还支持
导入头文件
#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];