A protocol that provides advance warning of the data requirements for a table view, allowing you to start potentially long-running data operations early.
@MainActor 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:
tableView(_:cellForRowAt:)데이터 소스 메소드가 호출 되기 전에 셀에 대한 데이터 로드를 시작하기 위해 테이블 뷰의 데이터 소스와 prefetch 데이터 소스 객체를 함께 사용합니다.
테이블 뷰에 대한 prefetch 데이터 소스를 지원하려면 다음 단계가 필요합니다.
Create the table view and its regular data source.
Create an object that adopts the UITableViewDataSourcePrefetching
protocol, and assign it to the prefetchDataSource
property on the table view.
Initiate asynchronous loading of the data required for the cells at the specified index paths in your implementation of tableView(_:prefetchRowsAt:)
.
Prepare the cell for display using the prefetched data in your tableView(_:cellForRowAt:)
data source method.
Cancel pending data load operations when the table view informs you that the data is no longer required in the tableView(_:cancelPrefetchingForRowsAt:)
method.
Note
The prefetch method is not necessarily called for every cell in the table view. For details about a suggested approach to loading data, see Loading Data Asynchronously.
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
.