0413--iOS之UICollectionViewDataSource协议

Protocol

UICollectionViewDataSource            --协议,即提供给实现类复写的

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

       --管理collection view的cell数据并提供cell的对象,必须遵循该协议。该协议提供了一系列管理数据的方法。

 

Declaration              --声明

protocol UICollectionViewDataSource

 

Overview                  --概览

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。

 

Topics

Getting Item and Section Metrics                 --设置item和section的数量

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.

 

Getting Views for Items                           --设置items的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.

 

Reordering Items                         --对items重新排序

 

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.

 

Configuring an Index                       --配置索引

 

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.

 

Relationships                       --继承关系

Inherits From

NSObjectProtocol

Conforming Types

  • UICollectionViewController

  • UICollectionViewDiffableDataSource

  • UICollectionViewDiffableDataSourceReference

See Also

Data

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.

 

你可能感兴趣的:(IOS,API阅读,Collection,Views相关)