Looking through UICollectionView tutorials, I see some where UICollectionViewCell
is subclassed for items, and some where UICollectionReusableView
is subclassed instead. The docs don't make it very clear when you would use one over the other.
A view that defines the behavior for all cells and supplementary views presented by a collection view.
An object that manages an ordered collection of data items and presents them using customizable layouts.
collectionView(_:viewForSupplementaryElementOfKind:at:)Asks your data source object to provide a supplementary view to display in the collection view.
To display this section header, you'll use UICollectionReusableView . This class is like UICollectionViewCell , except it's usually used to display headers and footers. Like cells, UICollectionView places them in a reuse queue rather than deleting them when they scroll out of the visible bounds.
UICollectionViewCell
A UICollectionViewCell object presents the content for a single data item when that item is within the collection view’s visible bounds. You can use this class as-is or subclass it to add additional properties and methods. The layout and presentation of cells is managed by the collection view and its corresponding layout object.
UICollectionReusableView
The UICollectionReusableView class defines the behavior for all cells and supplementary views presented by a collection view. Reusable views are so named because the collection view places them on a reuse queue rather than deleting them when they are scrolled out of the visible bounds. Such a view can then be retrieved and repurposed for a different set of content.
So the difference is that a UICollectionViewCell
presents the content for a single data item and a UICollectionReusableView
class defines the behavior for all cells and supplementary views presented by a collection view.
Actually, Apple recommends that you use UICollectionViewCell
both for cells and for supplementary views. That way, you get the useful features such as the background view. UICollectionReusableView
is merely what makes these views reusable. So there is no important distinction except for the built-in superclass–subclass relationship.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With