Protocol: UICollectionViewDataSource
Overview
An object that adopts the UICollectionViewDataSource protocol is responsible for providing the data and views required by a collection view. A data source object represents your app’s data model and vends information to the collection view as needed. It also handles the creation and configuration of cells and supplementary views used by the collection view to display your data.Asks the data source for the cell that corresponds to the specified item in the collection view. (required)Asks the data source for the number of items in the specified section. (required)Asks the collection view to provide a supplementary view to display in the collection view.Asks the data source for the number of sections in the collection view.
Instance Method Summary (collapse)
-
- collectionView:cellForItemAtIndexPath:
Asks the data source for the cell that corresponds to the specified item in the collection view.
-
- collectionView:numberOfItemsInSection:
Asks the data source for the number of items in the specified section.
-
- collectionView:viewForSupplementaryElementOfKind:atIndexPath:
Asks the collection view to provide a supplementary view to display in the collection view.
-
- numberOfSectionsInCollectionView:
Asks the data source for the number of sections in the collection view.
Instance Method Details
- (UICollectionViewCell) collectionView(collectionView, cellForItemAtIndexPath:indexPath)
Asks the data source for the cell that corresponds to the specified item in the collection view. (required) Your implementation of this method is responsible for creating, configuring, and returning the appropriate cell for the given item. You do this by calling the dequeueReusableCellWithReuseIdentifier:forIndexPath: method of the collection view and passing the reuse identifier that corresponds to the cell type you want. That method always returns a valid cell object. Upon receiving the cell, you should set any properties that correspond to the data of the corresponding item, perform any additional needed configuration, and return the cell. You do not need to set the location of the cell inside the collection view’s bounds. The placement of cells is handled automatically by the layout object in conjunction with the collection view.
- (Integer) collectionView(collectionView, numberOfItemsInSection:section)
Asks the data source for the number of items in the specified section. (required)
- (UICollectionReusableView) collectionView(collectionView, viewForSupplementaryElementOfKind:kind, atIndexPath:indexPath)
Asks the collection view to provide a supplementary view to display in the collection view. Your implementation of this method is responsible for creating, configuring, and returning the appropriate supplementary view that is being requested. You do this by calling the dequeueReusableSupplementaryViewOfKind:withReuseIdentifier:forIndexPath: method of the collection view and passing the information that corresponds to the view you want. That method always returns a valid view object. Upon receiving the view, you should set any properties that correspond to the data you want to display, perform any additional needed configuration, and return the view. You do not need to set the location of the supplementary view inside the collection view’s bounds. The placement of supplementary views is handled automatically by the layout object in conjunction with the collection view.
- (Integer) numberOfSectionsInCollectionView(collectionView)
Asks the data source for the number of sections in the collection view. If you do not implement this method, the collection view uses a default value of 1.