Contents

UICollectionViewCellRegistration

A registration for the collection view’s cells.

Declaration

@interface UICollectionViewCellRegistration : NSObject

Overview

Use a cell registration to register cells with your collection view and configure each cell for display. You create a cell registration with your cell type and data item type as the registration’s generic parameters, passing in a registration handler to configure the cell. In the registration handler, you specify how to configure the content and appearance of that type of cell.

The following example creates a cell registration for cells of type UICollectionViewListCell. It creates a content configuration with a system default style, customizes the content and appearance of the configuration, and then assigns the configuration to the cell.

UICollectionViewCellRegistration *cellRegistration = [UICollectionViewCellRegistration registrationWithCellClass:[UICollectionViewListCell class] configurationHandler:^(UICollectionViewListCell *cell, NSIndexPath *indexPath, id item) {
    UIListContentConfiguration *contentConfiguration = cell.defaultContentConfiguration;
    
    contentConfiguration.text = [NSString stringWithFormat:@"%@", item];
    contentConfiguration.textProperties.color = UIColor.lightGrayColor;
    
    cell.contentConfiguration = contentConfiguration;
}];

After you create a cell registration, you pass it in to dequeueConfiguredReusableCellWithRegistration:forIndexPath:item:, which you call from your data source’s cell provider.

self.dataSource = [[UICollectionViewDiffableDataSource alloc] initWithCollectionView:self.collectionView cellProvider:^UICollectionViewCell *(UICollectionView *collectionView, NSIndexPath *indexPath, id item) {
    return [collectionView dequeueConfiguredReusableCellWithRegistration:cellRegistration forIndexPath:indexPath item:item];
}];

You don’t need to call register(_:forCellWithReuseIdentifier:) or register(_:forCellWithReuseIdentifier:). The collection view registers your cell automatically when you pass the cell registration to dequeueConfiguredReusableCellWithRegistration:forIndexPath:item:.

Topics

Creating a cell registration

Querying a cell registration

See Also

Creating cells