TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | May 2015 |
Maintained by Michael Kamphausen, cg, Tino Rachui, Mathias Köhnke, Mathias Koehnke, Nico Schümann, Heiko Wichmann, Stephan Lerner, Famara Kassama.
UITableViewDataSource for NSArray. A UITableViewDataSource for data represented as NSArray being displayed in a UITableView.
Concept and code is from this great objc.io article.
Additionally supports:
Import header file:
#import "ALArrayDataSource.h"
Declare a dataSource property:
@property (nonatomic, strong) ALArrayDataSource* dataSource;
Init dataSource with your data array (empty here), cell identifier, a block for configuring the tableView cells and set the tableView dataSource:
self.dataSource = [[ALArrayDataSource alloc] initWithItems:@[] cellIdentifier:@"CellIdentifier" configureCellBlock:[self configureCell]];
self.tableView.dataSource = self.dataSource;
Declare a method returning a block for configuring the tableView cell:
- (TableViewCellConfigureBlock)configureCell {
return ^(UITableViewCell* cell, id yourModel) {
cell.textLabel.text = yourModel.name;
cell.imageView.image = yourModel.image;
};
}
When you retrieve new data, update your dataSource and tableView like this:
self.dataSource.items = modelArray;
[self.tableView reloadData];