A protocol that provides advance warning of the data requirements for a collection view, allowing the triggering of asynchronous data load operations.


@protocol UICollectionViewDataSourcePrefetching


You use a prefetch data source object in conjunction with your collection view’s data source to begin loading data for cells before the collectionView:cellForItemAtIndexPath: data source method is called.The following steps are required to add a prefetch data source to your collection view:

When configuring the collection view object, assign your prefetch data source to its prefetchDataSource property. For more information about how a collection view works, see UICollectionView.

Loading Data Asynchronously

The collectionView:prefetchItemsAtIndexPaths: method is not necessarily called for every cell in the collection view. Your implementation of collectionView:cellForItemAtIndexPath: must therefore be able to cope with the following potential situations:

  • Data has been loaded via the prefetch request, and is ready to be displayed.

  • Data is currently being prefetched, but is not yet available.

  • Data has not yet been requested.

One approach that handles all of these situations is to use NSOperation to load the data for each row. You create the NSOperation object and store it in the prefetch method. The data source method can then either retrieve the operation and the result, or create it if it doesn’t exist. For further information about how you can use asynchronous programming models to achieve this desired behavior, see Concurrency Programming Guide.


Managing Data Prefetching

Prefetching Collection View Data

Load data for collection view cells before they are displayed.

- collectionView:prefetchItemsAtIndexPaths:

Instructs your prefetch data source object to begin preparing data for the cells at the supplied index paths.


- collectionView:cancelPrefetchingForItemsAtIndexPaths:

Cancels a previously triggered data prefetch request.


Inherits From

See Also



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.