Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
The most simple and robust way to manage UITableView

README.md

Build Status   CocoaPod platform   CocoaPod version   License MIT

DTTableViewManager

This is a sister-project for DTCollectionViewManager - great tool for UICollectionView management, built on the same principles.

Target of this project is to create powerful architecture for UITableView сontrollers. It combines several ideas to make UITableView management easy, clean, and delightful.

Try it out! =)

pod try DTTableViewManager

Features

  • Powerful mapping system between data models and table view cells, headers and footers
  • Automatic datasource and interface synchronization.
  • Support for creating cells from XIBs or storyboards.
  • Support for UITableViewHeaderFooterView or custom UIView for table headers and footers
  • Easy UITableView search
  • Core data / NSFetchedResultsController support
  • Swift support

Quick start

Let's say you have an array of Posts you want to display in UITableView. To quickly show them using DTTableViewManager, here's what you need to do:

Subclass DTTableViewController, create xib, or storyboard with your view controller, wire up tableView outlet. Add following code to viewDidLoad:

[self registerCellClass:[PostCell class] forModelClass:[Post class]];
[self.memoryStorage addItems:posts];

or in Swift:

self.registerCellClass(PostCell.self, forModelClass:Post.self)
self.memoryStorage().addItems(posts)

Subclass DTTableViewCell, and implement updateWithModel method

-(void)updateWithModel:(id)model
{
    Post * post = model;
    self.postTextView.text = post.content;
}

or in Swift:

func updateWithModel(model: AnyObject!)
{
    let post = model as Post
    self.postTextView.text = post.content
}

That's it! For more detailed look at available API - API quickstart page on wiki.

Mapping and registration

Registering cell class and xib is 1 line of code:

[self registerCellClass:[Cell class] forModelClass:[Model class]];

Similarly, for headers and footers:

[self registerHeaderClass:[HeaderView class] forModelClass:[Model class]];
[self registerFooterClass:[FooterView class] forModelClass:[Model class]];

For more detailed look at mapping in DTTableViewManager, check out dedicated Mapping wiki page.

Managing table items

Storage classes for DTTableViewManager have been moved to separate repo. Two data storage classes are provided - memory and core data storage.

Memory storage

DTMemoryStorage encapsulates storage of table view data models in memory. It's basically NSArray of DTSectionModel objects, which contain array of objects for current section, section header and footer model.

You can take a look at all provided methods for manipulating items here: DTMemoryStorage methods

DTTableViewManager adds several methods to DTMemoryStorage, that are specific to UITableView. Take a look at them here: DTMemoryStorage additions

NSFetchedResultsController and DTCoreDataStorage

DTCoreDataStorage is meant to be used with NSFetchedResultsController. It automatically monitors all NSFetchedResultsControllerDelegate methods and updates UI accordingly to it's changes. All you need to do to display CoreData models in your UITableView, is create DTCoreDataStorage object and set it on your DTTableViewController subclass.

self.dataStorage = [DTCoreDataStorage storageWithFetchResultsController:controller];

Important Keep in mind, that DTMemoryStorage is not limited to objects in memory. For example, if you have CoreData database, and you now for sure, that number of items is not big, you can choose not to use DTCoreDataStorage and NSFetchedResultsController. You can fetch all required models, and store them in DTMemoryStorage, just like you would do with NSObject subclasses.

Search

DTTableViewManager has a built-in search system, that is easy to use and flexible. Read all about it in a dedicated Implementing search wiki page.

Requirements

  • iOS 7.x, 8.x
  • ARC

Installation

Simplest option is to use CocoaPods:

pod 'DTTableViewManager', '~> 3.0.0'

Documentation

You can view documentation online or you can install it locally using cocoadocs!

Also check out wiki page for lot's of information on DTTableViewManager internals and best practices.

Thanks

  • Alexey Belkevich for providing initial implementation of CellFactory.
  • Michael Fey for providing insight into NSFetchedResultsController updates done right.
  • Nickolay Sheika for great feedback, that helped shaping 3.0 release.
Something went wrong with that request. Please try again.