NimbusKit
1.2.1 - Fork Nimbus on Github - Visit the Nimbus Wiki
The iOS framework that grows only as fast as its documentation
|
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.
Tasks | |
(UITableViewCell *) | + tableViewModel:cellForTableView:atIndexPath:withObject: |
(void) | - mapObjectClass:toCellClass: |
(CGFloat) | - tableView:heightForRowAtIndexPath:model: |
(CGFloat) | + tableView:heightForRowAtIndexPath:model: |
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:
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.
Reimplemented from <NITableViewModelDelegate>.
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.
Returns the height for a row at a given index path.
Uses the heightForObject:atIndexPath:tableView: selector from the NICell protocol to ask the object at indexPath in the model what its height should be. If a class mapping has been made for the given object in this factory then that class mapping will be used over the result of cellClass from the NICellObject protocol.
If the cell returns a height of zero then tableView.rowHeight will be used.
Example implementation:
tableView | The table view within which the cell exists. |
indexPath | The location of the cell in the table view. |
model | The backing model being used by the table view. |
Returns the height for a row at a given index path.
Uses the heightForObject:atIndexPath:tableView: selector from the NICell protocol to ask the object at indexPath in the model what its height should be. Only implicit mappings will be checked with this static implementation. If you would like to provide explicit mappings you must create an instance of NICellFactory.
If the cell returns a height of zero then tableView.rowHeight will be used.
Example implementation:
tableView | The table view within which the cell exists. |
indexPath | The location of the cell in the table view. |
model | The backing model being used by the table view. |