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

Overview

A non-mutable collection view model that complies to the UICollectionViewDataSource protocol.

This model allows you to easily create a data source for a UICollectionView without having to implement the UICollectionViewDataSource methods in your controller.

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

This model simply manages the data relationship with your collection view. It is up to you to implement the collection view's layout object.

Inheritance diagram for NICollectionViewModel:
NIMutableCollectionViewModel

Tasks

Creating Collection View Cells
id< NICollectionViewModelDelegatedelegate property
 
Creating Collection View Models
(id) - initWithDelegate:
 
(id) - initWithListArray:delegate:
 
(id) - initWithSectionedArray:delegate:
 
Accessing Objects
(id) - objectAtIndexPath:
 
(NSIndexPath *) - indexPathForObject:
 

Method Documentation

delegate

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

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

initWithDelegate:

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

- (id)initWithDelegate:(id<NICollectionViewModelDelegate>)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 *)listArray delegate:(id<NICollectionViewModelDelegate>)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];
[[NICollectionViewModel 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<NICollectionViewModelDelegate>)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"],
[NICollectionViewModelFooter footerWithTitle:@"Footer"],
nil];
[[NICollectionViewModel 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.