The iOS framework that grows only as fast as its documentation
NITableViewModel Class Reference

Overview

A non-mutable table view model that complies to the UITableViewDataSource protocol.

This model allows you to easily create a data source for a UITableView without having to implement the UITableViewDataSource methods in your UITableViewController.

This base class is non-mutable, much like an NSArray. You must initialize this model with the contents when you create it.

Examples:
ExampleStaticTableModel.m.
Inheritance diagram for NITableViewModel:
NIMutableTableViewModel

Tasks

Configuration
NITableViewModelSectionIndex sectionIndexType property
 
BOOL sectionIndexShowsSearch property
 
BOOL sectionIndexShowsSummary property
 
(void) - setSectionIndexType:showsSearch:showsSummary:
 
Creating Table View Cells
id< NITableViewModelDelegatedelegate property
 
NITableViewModelCellForIndexPathBlock createCellBlock property
 
Creating Table View Models
(id) - initWithDelegate:
 
(id) - initWithListArray:delegate:
 
(id) - initWithSectionedArray:delegate:
 
Accessing Objects
(id) - objectAtIndexPath:
 
(NSIndexPath *) - indexPathForObject:
 

Method Documentation

sectionIndexType

The section index type.

@property (nonatomic, readonly) NITableViewModelSectionIndex sectionIndexType;
Discussion

You will likely use NITableViewModelSectionIndexAlphabetical in practice.

NITableViewModelSectionIndexNone by default.

sectionIndexShowsSearch

Whether or not the search symbol will be shown in the section index.

@property (nonatomic, readonly) BOOL sectionIndexShowsSearch;
Discussion

NO by default.

sectionIndexShowsSummary

Whether or not the summary symbol will be shown in the section index.

@property (nonatomic, readonly) BOOL sectionIndexShowsSummary;
Discussion

NO by default.

delegate

A delegate used to fetch table view cells for the data source.

@property (nonatomic, weak) id<NITableViewModelDelegate> delegate;

createCellBlock

A block used to create a UITableViewCell for a given object.

@property (nonatomic, copy) NITableViewModelCellForIndexPathBlock createCellBlock;

initWithDelegate:

Initializes a newly allocated static model with the given delegate and empty contents.

- (id)initWithDelegate:(id<NITableViewModelDelegate>)delegate;
Discussion

This method can be used to create an empty model.

initWithListArray:delegate:

Initializes a newly allocated static model with the contents of a list array.

- (id)initWithListArray:(NSArray *)sectionedArray delegate:(id<NITableViewModelDelegate>)delegate;
Discussion

A list array is a one-dimensional array that defines a flat list of rows. There will be no sectioning of contents in any way.

Example

NSArray* contents =
[NSArray arrayWithObjects:
[NSDictionary dictionaryWithObject:@"Row 1" forKey:@"title"],
[NSDictionary dictionaryWithObject:@"Row 2" forKey:@"title"],
[NSDictionary dictionaryWithObject:@"Row 3" forKey:@"title"],
nil];
[[NIStaticTableViewModel alloc] initWithListArray:contents delegate:self];

initWithSectionedArray:delegate:

Initializes a newly allocated static model with the contents of a sectioned array.

- (id)initWithSectionedArray:(NSArray *)sectionedArray delegate:(id<NITableViewModelDelegate>)delegate;
Discussion

A sectioned array is a one-dimensional array that defines a list of sections and each section's contents. Each NSString begins a new section and any other object defines a row for the current section.

Example

NSArray* contents =
[NSArray arrayWithObjects:
@"Section 1",
[NSDictionary dictionaryWithObject:@"Row 1" forKey:@"title"],
[NSDictionary dictionaryWithObject:@"Row 2" forKey:@"title"],
@"Section 2",
// This section is empty.
@"Section 3",
[NSDictionary dictionaryWithObject:@"Row 3" forKey:@"title"],
[NITableViewModelFooter footerWithTitle:@"Footer"],
nil];
[[NIStaticTableViewModel alloc] initWithSectionedArray:contents delegate:self];

objectAtIndexPath:

Returns the object at the given index path.

- (id)objectAtIndexPath:(NSIndexPath *)indexPath;
Discussion

If no object exists at the given index path (an invalid index path, for example) then nil will be returned.

indexPathForObject:

Returns the index path of the given object within the model.

- (NSIndexPath*)indexPathForObject:(id)object;
Discussion

If the model does not contain the object then nil will be returned.

setSectionIndexType:showsSearch:showsSummary:

Configures the model's section index properties.

- (void)setSectionIndexType:(NITableViewModelSectionIndex)sectionIndexType showsSearch:(BOOL)showsSearch showsSummary:(BOOL)showsSummary;
Discussion

Calling this method will compile the section index depending on the index type chosen.

Parameters
sectionIndexTypeThe type of section index to display.
showsSearchWhether or not to show the search icon at the top of the index.
showsSummaryWhether or not to show the summary icon at the bottom of the index.