Click here to support Nimbus development and make a donation at www.pledgie.com !
An iOS framework whose growth is bounded by O(documentation).
NICellFactory Class Reference

Overview

A simple factory for creating table view cells from objects.

This factory provides a single method that accepts an object and returns a UITableViewCell for use in a UITableView. A cell will only be returned if the object passed to the factory conforms to the NICellObject protocol. The created cell should ideally conform to the NICell protocol. If it does, the object will be passed to it via shouldUpdateCellWithObject: before the factory method returns.

This factory is designed to be used with NITableViewModels, though one could easily use it with other table view data source implementations simply by providing nil for the table view model.

If you instantiate an NICellFactory then you can provide explicit mappings from objects to cells. This is helpful if the effort required to implement the NICell protocol on an object outweighs the benefit of using the factory, i.e. when you want to map simple types such as NSString to cells.

Definition at line 43 of file NICellFactory.h.

Inheritance diagram for NICellFactory:
<NITableViewModelDelegate>

Methods

(UITableViewCell *) + tableViewModel:cellForTableView:atIndexPath:withObject:
(void) - mapObjectClass:toCellClass:

Method Documentation

+ (UITableViewCell *) tableViewModel: (NITableViewModel *)  tableViewModel
cellForTableView: (UITableView *)  tableView
atIndexPath: (NSIndexPath *)  indexPath
withObject: (id)  object 

Creates a cell from a given object if and only if the object conforms to the NICellObject protocol.

This method signature matches the NITableViewModelDelegate method so that you can set this factory as the model's delegate:

// Must cast to id to avoid compiler warnings.
_model.delegate = (id)[NICellFactory class];

If you would like to customize the factory's output, implement the model's delegate method and call the factory method. Remember that if the factory doesn't know how to map the object to a cell it will return nil.

- (UITableViewCell *)tableViewModel: (NITableViewModel *)tableViewModel
                   cellForTableView: (UITableView *)tableView
                        atIndexPath: (NSIndexPath *)indexPath
                         withObject: (id)object {
  UITableViewCell* cell = [NICellFactory tableViewModel: tableViewModel
                                       cellForTableView: tableView
                                            atIndexPath: indexPath
                                             withObject: object];
  if (nil == cell) {
    // Custom cell creation here.
  }
  return cell;
}

Reimplemented from <NITableViewModelDelegate>.

Definition at line 79 of file NICellFactory.m.

- (void) mapObjectClass: (Class)  objectClass
toCellClass: (Class)  cellClass 

Map an object's class to a cell's class.

If an object implements the NICell protocol AND is found in this factory mapping, the factory mapping will take precedence. This allows you to explicitly override the mapping on a case-by-case basis.

Definition at line 120 of file NICellFactory.m.

Generated for Nimbus by doxygen 1.7.4-20110629