Latest 0.9.5
Homepage https://github.com/OliverLetterer/SPLTableViewBehavior
License MIT
Platforms ios 8.0, requires ARC
Frameworks UIKit
Authors

[![CI Status](http://img.shields.io/travis/Oliver Letterer/SPLTableViewBehavior.svg?style=flat)](https://travis-ci.org/Oliver Letterer/SPLTableViewBehavior)
Version
License
Platform

The goal of this project is to define a whole UITableView behavior by providing lightweight, reusable and composable UITableViewDataSources/Delegates components.

Usage

SPLTableViewBehavior

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
}];

SPLArrayBehavior

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);
}];

SPLFetchedResultsBehavior

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;
}];

SPLSectionBehavior

Group’s multiple behaviors into one section

NSArray *behaviors = @[ behavior1, behavior2, behavior3 ];

SPLSectionBehavior *behavior = [[SPLSectionBehavior alloc] initWithTitle:@"Section 0" behaviors:behaviors];

SPLCompoundBehavior

Display’s multiple behaviors with it’s own section

NSArray *behaviors = @[ behavior1, behavior2, behavior3 ];

self.behavior = [[SPLCompoundBehavior alloc] initWithBehaviors:behaviors];

Hook it up

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;
}

Installation

SPLTableViewBehavior is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "SPLTableViewBehavior"

Author

Oliver Letterer, [email protected]

License

SPLTableViewBehavior is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "SPLTableViewBehavior",
    "version": "0.9.5",
    "summary": "Define a UITableView behavior with lightweight, reusable and composable components.",
    "homepage": "https://github.com/OliverLetterer/SPLTableViewBehavior",
    "license": "MIT",
    "authors": {
        "Oliver Letterer": "[email protected]"
    },
    "source": {
        "git": "https://github.com/OliverLetterer/SPLTableViewBehavior.git",
        "tag": "0.9.5"
    },
    "social_media_url": "https://twitter.com/oletterer",
    "platforms": {
        "ios": "8.0"
    },
    "requires_arc": true,
    "source_files": [
        "SPLTableViewBehavior",
        "SPLTableViewBehavior/Private"
    ],
    "private_header_files": "SPLTableViewBehavior/Private/*.h",
    "frameworks": "UIKit"
}

Pin It on Pinterest

Share This