Protocol
The methods adopted by the object you use to manage data and provide cells for a collection view.
--管理collection view的cell数据并提供cell的对象,必须遵循该协议。该协议提供了一系列管理数据的方法。
protocol UICollectionViewDataSource
A data source object manages the data in your collection view. It represents your app's data model and vends information to the collection view as needed. It also creates and configures the cells and supplementary views used by the collection view to display your data.
--data source object管理collection view中的数据。它表示app的数据模型,并根据需要向collection view提供信息。它还创建和配置集合视图中的用于显示数据的单元格和补充视图。
At a minimum, all data source objects must implement the collectionView(_:numberOfItemsInSection:)
and collectionView(_:cellForItemAt:)
methods. These methods are responsible for returning the number of items in the collection view along with the items themselves. The remaining methods of the protocol are optional and only needed if your collection view organizes items into multiple sections or provides headers and footers for a given section.
--至少,所有data source objects 都必须实现协议中的 collectionView(_:numberOfItemsInSection:)
和collectionView(_:cellForItemAt:)
方法。这些方法负责返回collection view中的item数目以及item本身。协议的其余方法是可选的,只有在collection view中需要将items组织进多个section中 或 为指定section提供页眉和页脚时 才会用到。
When configuring the collection view object, assign your data source to its dataSource
property. For more information about how a collection view works with its data source to present content, see UICollectionView
.
--配置collection view对象时,请将数据源分配给collection view的dataSource
属性。有关集合视图如何与其数据源一起工作以显示内容的详细信息,请参阅 UICollectionView。
func collectionView(UICollectionView, numberOfItemsInSection: Int) -> Int
Asks your data source object for the number of items in the specified section.
Required. --必须实现的方法
func numberOfSections(in: UICollectionView) -> Int
Asks your data source object for the number of sections in the collection view.
func collectionView(UICollectionView, cellForItemAt: IndexPath) -> UICollectionViewCell
Asks your data source object for the cell that corresponds to the specified item in the collection view.
Required. --必须实现的方法
func collectionView(UICollectionView, viewForSupplementaryElementOfKind: String, at: IndexPath) -> UICollectionReusableView
Asks your data source object to provide a supplementary view to display in the collection view.
func collectionView(UICollectionView, canMoveItemAt: IndexPath) -> Bool
Asks your data source object whether the specified item can be moved to another location in the collection view.
func collectionView(UICollectionView, moveItemAt: IndexPath, to: IndexPath)
Tells your data source object to move the specified item to its new location.
func indexTitles(for: UICollectionView) -> [String]?
Asks the data source to return the titles for the index items to display for the collection view.
func collectionView(UICollectionView, indexPathForIndexTitle: String, at: Int) -> IndexPath
Asks the data source to return the index path of a collection view item that corresponds to one of your index entries.
NSObjectProtocol
UICollectionViewController
UICollectionViewDiffableDataSource
UICollectionViewDiffableDataSourceReference
class UICollectionViewDiffableDataSource
struct NSDiffableDataSourceSnapshot
protocol UICollectionViewDataSourcePrefetching
A protocol that provides advance warning of the data requirements for a collection view, allowing the triggering of asynchronous data load operations.