A protocol that provides advance warning of the data requirements for a table view, allowing you to start potentially long-running data operations early.


protocol UITableViewDataSourcePrefetching


You use a prefetch data source object in conjunction with your table view’s data source to begin loading data for cells before the tableView(_:cellForRowAt:) data source method is called. The following steps are required to support a prefetch data source to your table view:

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

Loading Data Asynchronously

The tableView(_:prefetchRowsAt:) method is not necessarily called for every cell in the table view. Your implementation of tableView(_:cellForRowAt:) 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 Operation to load the data for each row. You create the Operation 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.


Fetching the Row Data

func tableView(UITableView, prefetchRowsAt: [IndexPath])

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


func tableView(UITableView, cancelPrefetchingForRowsAt: [IndexPath])

Cancels a previously triggered data prefetch request.


Inherits From

See Also


Filling a Table with Data

Create and configure cells for your table dynamically using a data source object, or provide them statically from your storyboard.

protocol UITableViewDataSource

The methods adopted by the object you use to manage data and provide cells for a table view.

class UILocalizedIndexedCollation

An object that organizes, sorts, and localizes the data for a table view that has a section index.

protocol UIDataSourceTranslating

An advanced interface for managing a data source object.

class UIRefreshControl

A standard control that can initiate the refreshing of a scroll view’s contents.

Asynchronously Loading Images into Table and Collection Views

Store and fetch images asynchronously to make your app more responsive.