Declared in SCTableViewModel.h

Overview

This protocol should be adopted by objects that want to mediate as a data source for SCTableViewModel. All methods for this protocol are optional.

Tasks

Section Management

Custom cells

Custom detail views

  • – tableViewModel:detailTableViewModelForRowAtIndexPath:

    Asks the dataSource to provide a custom detail table view model for the specified cell. This custom table view model will be used to render the cell’s details instead of the default automatically generated detail model. The returned model is typically a blank model with no sections (all content will be generated by the requesting cell).

  • – tableViewModel:detailViewControllerForRowAtIndexPath:

    Asks the dataSource to provide a custom detail view controller for the specified cell. This custom detail view will be used to render the cell’s details instead of the default automatically generated detail view controller.

Inserting, Deleting, or Moving Model Rows

SCArrayOfItemsModel methods

SCArrayOfItemsSection methods

Instance Methods

tableViewModel:cellForRowAtIndexPath:

Asks the dataSource to provide a custom cell for the specified indexPath. Implement this method to provide your own custom cells instead of the automatically generated cells by SCArrayOfItemsSection and its subclasses.

- (SCCustomCell *)tableViewModel:(SCTableViewModel *)tableModel cellForRowAtIndexPath:(NSIndexPath *)indexPath

Parameters

tableModel

The model requesting the custom cell.

indexPath

The index path of the row whose custom cell is requested.

Discussion

Note: Returning “nil” will have the section provide an automatically generated cell.

Warning: If more than one cell type is returned (including returning “nil”), then the tableViewModel:customReuseIdentifierForRowAtIndexPath: method must be implemented, returning a unique reuse identifier for each cell type used.

Declared In

SCTableViewModel.h

tableViewModel:commitEditingStyle:forRowAtIndexPath:

Asks the dataSource to handle to the insertion or deletion of the specified row in the model.

- (void)tableViewModel:(SCTableViewModel *)tableModel commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

Parameters

tableModel

The model requesting the insertion or deletion.

editingStyle

The cell editing style corresponding to a insertion or deletion requested for the row specified by indexPath. Possible editing styles are UITableViewCellEditingStyleInsert or UITableViewCellEditingStyleDelete.

indexPath

The index path locating the row in the model.

Discussion

Warning: It is very rare when you’ll need to define this method. If you are using an SCArrayOfItemsSection or any of its subclasses, the insertion and deletion of rows will be handeled for you automatically.

Declared In

SCTableViewModel.h

tableViewModel:customSearchResultForSearchText:autoSearchResults:

Asks the dataSource to return a custom search result array given the search text and the results array automatically generated by the model.

- (NSArray *)tableViewModel:(SCArrayOfItemsModel *)tableModel customSearchResultForSearchText:(NSString *)searchText autoSearchResults:(NSArray *)autoSearchResults

Parameters

tableModel

The model requesting the custom search result.

searchText

The search text typed into the search bar.

autoSearchResults

The search results array automatically generated by the model. The type of objects in the results array is identical to the type of objects in the tableViewModel items array.

Return Value

The method should return an autoreleased NSArray results array. Important: The type of objects in the results array must be identical to the type of objects in the tableViewModel items array. Note: Return nil to ignore the custom search results and use autoSearchResults instead.

Declared In

SCTableViewModel.h

tableViewModel:detailTableViewModelForRowAtIndexPath:

Asks the dataSource to provide a custom detail table view model for the specified cell. This custom table view model will be used to render the cell’s details instead of the default automatically generated detail model. The returned model is typically a blank model with no sections (all content will be generated by the requesting cell).

- (SCTableViewModel *)tableViewModel:(SCTableViewModel *)tableModel detailTableViewModelForRowAtIndexPath:(NSIndexPath *)indexPath

Parameters

tableModel

The model requesting the custom detail table view model.

indexPath

The index path of the cell whose detail table view model is requested.

Return Value

The custom detail table view model. This model should be autoreleased and is typically a blank model that the requesting cell will generate the content for.

Discussion

Warning: This method should only be implemented for cells that require a detail UITableView to display their contents. For cells that do not require a detail UITableView (e.g.: SCImagePickerCell), you should implement the tableViewModel:detailViewForRowAtIndexPath: method instead.

Note: This method is typically used to display the cell’s details in the detail view of an Pad’s UISplitViewController.

Declared In

SCTableViewModel.h

tableViewModel:detailViewControllerForRowAtIndexPath:

Asks the dataSource to provide a custom detail view controller for the specified cell. This custom detail view will be used to render the cell’s details instead of the default automatically generated detail view controller.

- (UIViewController *)tableViewModel:(SCTableViewModel *)tableModel detailViewControllerForRowAtIndexPath:(NSIndexPath *)indexPath

Parameters

tableModel

The model requesting the custom detail view controller.

indexPath

The index path of the cell whose detail view controller is requested.

Return Value

The custom detail view controller. This view controller is typically a blank view controller that the requesting cell will generate the content for.

Discussion

Warning: This method should only be implemented for cells that do not require a detail UITableView to display their contents (e.g.: SCImagePickerCell). For all other cells that do require a detail UITableView, you should implement the tableViewModel:customTableViewModelForRowAtIndexPath: method instead.

Note: This method is typically used to display the cell’s details in the detail view of an iPad’s UISplitViewController.

Declared In

SCTableViewModel.h

tableViewModel:moveRowAtIndexPath:toIndexPath:

Asks the dataSource to handle to the movement of the specified row in the model from a specified location to another.

- (void)tableViewModel:(SCTableViewModel *)tableModel moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath

Parameters

tableModel

The model requesting the row movement.

fromIndexPath

The starting index path of the row to be moved.

toIndexPath

The destination index path of the move.

Discussion

Warning: It is very rare when you’ll need to define this method. If you are using an SCArrayOfItemsSection or any of its subclasses, the movement of rows will be handeled for you automatically.

Declared In

SCTableViewModel.h

tableViewModel:newItemForArrayOfItemsSectionAtIndex:

Asks the dataSource to handle the creation of a new item in an SCArrayOfItemsSection.

- (NSObject *)tableViewModel:(SCTableViewModel *)tableModel newItemForArrayOfItemsSectionAtIndex:(NSUInteger)index

Parameters

tableModel

The model requesting owning the array of objects section.

index

The index of the array of items section requesting the new item.

Return Value

The method should return an autoreleased new item that is a subclass of NSObject.

Discussion

When there is an attempt to create a new array item in an SCArrayOfItemsSection, the dataSource is asked to provide this new item. If the dataSource does not define this method, SCArrayOfItemsSection creates an item of the same class as the first item in the array (unless SCArrayOfObjectsSection is being used, in which case the provided class definition will be used to create the new object). If no items are in the array, and this method is not defined, no new objects can be created.

Declared In

SCTableViewModel.h

tableViewModel:reuseIdentifierForRowAtIndexPath:

Asks the dataSource to provide a custom reuse identifier for the specified indexPath. Implement this method to provide your own custom reuse identifiers for cells generated by SCArrayOfItemsSection and its subclasses.

- (NSString *)tableViewModel:(SCTableViewModel *)tableModel reuseIdentifierForRowAtIndexPath:(NSIndexPath *)indexPath

Parameters

tableModel

The model requesting the custom reuse identifier.

indexPath

The index path of the row whose custom reuse identifier is requested.

Discussion

Warning: This method must be implemented if more than one type of cell is returned in tableViewModel:cellForRowAtIndexPath: (including returning “nil”), where it should return a unique reuse identifier for each cell type used. If only one cell type is returned in tableViewModel:cellForRowAtIndexPath:, then there is no need to implement this method.

Declared In

SCTableViewModel.h

tableViewModel:sectionHeaderTitleForItem:AtIndex:

Asks the dataSource to return the section header title for the given item index.

- (NSString *)tableViewModel:(SCArrayOfItemsModel *)tableModel sectionHeaderTitleForItem:(NSObject *)item AtIndex:(NSUInteger)index

Parameters

tableModel

The model requesting the section header title.

item

The item whose setion header title is requested.

index

The index of item in SCArrayOfItemsModel.

Return Value

The method should return an autoreleased NSString header title.

Declared In

SCTableViewModel.h

tableViewModel:sortSections:

Asks the dataSource to provide custom sorting for the model’s sections.

- (void)tableViewModel:(SCTableViewModel *)tableModel sortSections:(NSMutableArray *)sectionsArray

Parameters

tableModel

The model requesting the sorted sections array.

sectionsArray

The array containing the sections to be sorted. All objects of the array are of type SCTableViewSection.

Discussion

Note: If you just need to sort the sections alphabetically, just set your model’s autoSortSections property to TRUE.

Declared In

SCTableViewModel.h

tableViewModelSectionHeaderTitles:

Asks the dataSource to return a list of section header titles.

- (NSArray *)tableViewModelSectionHeaderTitles:(SCArrayOfItemsModel *)tableModel

Parameters

tableModel

The model requesting the section header titles.

Return Value

An array of NSString section titles.

Declared In

SCTableViewModel.h