Conforms to NSObject
Declared in SDataGridDataSource.h
Availability
Related samples

Overview

The SDataGridDataSource protocol is adopted by an object that mediates the application’s data model for a ShinobiDataGrid object. The datasource is responsible for providing the necessary information to construct a ShinobiDataGrid object - such as the number of rows/sections and for populating cells for each coordinate in the grid.

Information relating to the style and appearance of the ShinobiDataGrid is provided by the object that conforms to the SDataGridDelegate protocol. In this manner, the data model and appearance of the grid are kept separate.

ShinobiDataGrid uses cell pooling to make your grid as memory efficient as possible. Cells that are not currently visible are returned to an internal cell pool for later use and cells that become visible due to users scrolling/panning are retrieved from this pool. This means that ShinobiDataGrid caches cells only for visible rows and columns, but caches styling objects for the entire grid. For this reason, an appropriate cell object is handed to the shinobiDataGrid:prepareCellForDisplay: method and is the primary method for populating cells.

Tasks

Configuring a ShinobiDataGrid

Customizing Section Headers

  • – shinobiDataGrid:titleForHeaderInSection:

    Asks the data source for the title of the movable portion of header of the specified section of the ShinobiDataGrid object. If you do not implement this method, a default title such as “Section 1” will be used. Returning nil will result in the specified section having a blank header.

  • – shinobiDataGrid:titleForFrozenHeaderInSection:

    Asks the data source for the title of the frozen portion of the header of the specified section of the ShinobiDataGrid object. If you do not implement this method a default title will be used. Returning nil will result in the specified section having a blank frozen header.

  • – shinobiDataGrid:viewForHeaderInSection:inFrame:

    Asks the data source for a view for the movable portion of header of the specified section of the ShinobiDataGrid object. If you do not implement this method, the shinobiGrid:titleForHeaderInSection: delegate method is used as a fallback. Returning nil will also cause the title method to be used. The frame parameter specifies the header’s bounds, which you can use to size your view appropriately

  • – shinobiDataGrid:viewForFrozenHeaderInSection:inFrame:

    Asks the data source for a view for the frozen portion of header of the specified section of the ShinobiDataGrid object. If you do not implement this method, the shinobiGrid:titleForFrozenHeaderInSection: delegate method is used as a fallback. Returning nil will also cause the title method to be used. The frame parameter specifies the header’s bounds, which you can use to size your view appropriately.

Instance Methods

numberOfSectionsInShinobiDataGrid:

Asks the data source to return the number of sections that the ShinobiDataGrid object should have.

- (NSUInteger)numberOfSectionsInShinobiDataGrid:(ShinobiDataGrid *)grid

Parameters

grid

The grid that is requesting this information.

Return Value

The number of sections that grid will have.

Discussion

This data source method is optional - if this method is not implemented the grid will have 1 section by default.

Warning: Important If 1 is returned in this method you MUST implement the SDataGridDelegate method ‘shinobiDataGrid:styleForSectionHeaderAtIndex:’ for that section to be displayed. The SDataGridDelegate method returns the SDataGridSectionHeaderStyle to be applied to your grid’s only section header. If this method is not implemented your section header WILL NOT be displayed.

Declared In

SDataGridDataSource.h

shinobiDataGrid:numberOfRowsInSection:

Asks the data source to return the number of rows that the a particular section within the ShinobiDataGrid object should have.

- (NSUInteger)shinobiDataGrid:(ShinobiDataGrid *)grid numberOfRowsInSection:(NSInteger)sectionIndex

Parameters

grid

The grid that contains the section that is requesting the information.

sectionIndex

The index of the section that will have the number of rows returned.

Return Value

The number of rows that the specified section will have within the grid.

Declared In

SDataGridDataSource.h

shinobiDataGrid:prepareCellForDisplay:

This is the primary datasource method that gives you the opportunity to apply data/content to a cell prior to its appearance in the grid.

- (void)shinobiDataGrid:(ShinobiDataGrid *)grid prepareCellForDisplay:(SDataGridCell *)cell

Discussion

Warning: Important The grid recycles cells for performance reasons. This means that any cell provided to you by this method may have already been used within the grid. It is therefore important to set all content on the cell for its given position ([SDataGridCell coord]) so that no artefacts from prior use are present when displayed.

Declared In

SDataGridDataSource.h

shinobiDataGrid:titleForFrozenHeaderInSection:

Asks the data source for the title of the frozen portion of the header of the specified section of the ShinobiDataGrid object. If you do not implement this method a default title will be used. Returning nil will result in the specified section having a blank frozen header.

- (NSString *)shinobiDataGrid:(ShinobiDataGrid *)grid titleForFrozenHeaderInSection:(NSInteger)section

Discussion

Warning: Important Implementing shinobiGrid:viewForFrozenHeaderInSection:inFrame: overrides this method

Declared In

SDataGridDataSource.h

shinobiDataGrid:titleForHeaderInSection:

Asks the data source for the title of the movable portion of header of the specified section of the ShinobiDataGrid object. If you do not implement this method, a default title such as “Section 1” will be used. Returning nil will result in the specified section having a blank header.

- (NSString *)shinobiDataGrid:(ShinobiDataGrid *)grid titleForHeaderInSection:(NSInteger)section

Discussion

Warning: Important Implementing shinobiGrid:viewForHeaderInSection:inFrame: overrides this method

Declared In

SDataGridDataSource.h

shinobiDataGrid:viewForFrozenHeaderInSection:inFrame:

Asks the data source for a view for the frozen portion of header of the specified section of the ShinobiDataGrid object. If you do not implement this method, the shinobiGrid:titleForFrozenHeaderInSection: delegate method is used as a fallback. Returning nil will also cause the title method to be used. The frame parameter specifies the header’s bounds, which you can use to size your view appropriately.

- (UIView *)shinobiDataGrid:(ShinobiDataGrid *)grid viewForFrozenHeaderInSection:(NSInteger)section inFrame:(CGRect)frame

Declared In

SDataGridDataSource.h

shinobiDataGrid:viewForHeaderInSection:inFrame:

Asks the data source for a view for the movable portion of header of the specified section of the ShinobiDataGrid object. If you do not implement this method, the shinobiGrid:titleForHeaderInSection: delegate method is used as a fallback. Returning nil will also cause the title method to be used. The frame parameter specifies the header’s bounds, which you can use to size your view appropriately

- (UIView *)shinobiDataGrid:(ShinobiDataGrid *)grid viewForHeaderInSection:(NSInteger)section inFrame:(CGRect)frame

Declared In

SDataGridDataSource.h