Instance Method

dequeueReusableCell(withReuseIdentifier:for:)

Returns a reusable cell object located by its identifier

Declaration

func dequeueReusableCell(withReuseIdentifier identifier: String, for indexPath: IndexPath) -> UICollectionViewCell

Parameters

identifier

The reuse identifier for the specified cell. This parameter must not be nil.

indexPath

The index path specifying the location of the cell. The data source receives this information when it is asked for the cell and should just pass it along. This method uses the index path to perform additional configuration based on the cell’s position in the collection view.

Return Value

A valid UICollectionReusableView object.

Discussion

Call this method from your data source object when asked to provide a new cell for the collection view. This method dequeues an existing cell if one is available or creates a new one based on the class or nib file you previously registered.

If you registered a class for the specified identifier and a new cell must be created, this method initializes the cell by calling its init(frame:) method. For nib-based cells, this method loads the cell object from the provided nib file. If an existing cell was available for reuse, this method calls the cell’s prepareForReuse() method instead.

See Also

Creating Collection View Cells

func register(AnyClass?, forCellWithReuseIdentifier: String)

Register a class for use in creating new collection view cells.

func register(UINib?, forCellWithReuseIdentifier: String)

Register a nib file for use in creating new collection view cells.

func register(AnyClass?, forSupplementaryViewOfKind: String, withReuseIdentifier: String)

Registers a class for use in creating supplementary views for the collection view.

func register(UINib?, forSupplementaryViewOfKind: String, withReuseIdentifier: String)

Registers a nib file for use in creating supplementary views for the collection view.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software