TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Sep 2016 |
Maintained by Oliver Letterer.
The goal of this project is to define a whole UITableView behavior by providing lightweight, reusable and composable UITableViewDataSources/Delegates components.
Display's a single cell
UITableViewCell *prototype = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"prototype"];
prototype.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
SPLTableViewBehavior *behavior = [[SPLTableViewBehavior alloc] initWithPrototype:prototype configurator:^(UITableViewCell *cell) {
// setup the table view cell
} handler:^{
// do something when tapped
}];
Display's an array of data
UITableViewCell *prototype = ...
NSArray *data = @[ @"Object 1", @"Object 2", @"Object 3" ];
SPLArrayBehavior *behavior = [[SPLArrayBehavior alloc] initWithPrototype:prototype data:data configurator:^(UITableViewCell *cell, NSString *object) {
cell.textLabel.text = @"Section 0";
cell.detailTextLabel.text = object;
} handler:^(NSString *object) {
NSLog(@"Do something with %@ when tapped", object);
}];
Display's an array of data backed by a NSFetchedResultsController
UITableViewCell *prototype = ...
NSFetchedResultsController *controller = ...
SPLFetchedResultsBehavior *behavior = [[SPLFetchedResultsBehavior alloc] initWithPrototype:dataPrototype controller:controller configurator:^(UITableViewCell *cell, ManagedObject *object) {
cell.textLabel.text = @"From CoreData";
cell.detailTextLabel.text = object.name;
}];
Group's multiple behaviors into one section
NSArray *behaviors = @[ behavior1, behavior2, behavior3 ];
SPLSectionBehavior *behavior = [[SPLSectionBehavior alloc] initWithTitle:@"Section 0" behaviors:behaviors];
Display's multiple behaviors with it's own section
NSArray *behaviors = @[ behavior1, behavior2, behavior3 ];
self.behavior = [[SPLCompoundBehavior alloc] initWithBehaviors:behaviors];
Bind your final behavior to your UITableView
- (void)viewDidLoad
{
[super viewDidLoad];
self.behavior.update = self.tableView.update;
self.tableView.dataSource = self.behavior;
self.tableView.delegate = self.behavior;
}
Oliver Letterer, [email protected]
SPLTableViewBehavior is available under the MIT license. See the LICENSE file for more info.