UICollectionView: registerClass() method
The registerClass() method registers a kind of cell and gives it a reuse identifier. You then get cells by that reuse identifier inside cellProvider.
Syntax
registerClass(cellClass, { forCellWithReuseIdentifier })Parameters
cellClass
The cell class itself: UICollectionViewCell or UICollectionViewListCell. List layouts use UICollectionViewListCell.
options.forCellWithReuseIdentifier
The reuse identifier, a non-empty string, required. A reuse identifier means "which kind of cell"; it's different from an item identifier.
Return value
None (undefined).
Exceptions
TypeError
cellClassisn't a cell class (for exampleUIView, or a string):registerClass needs UICollectionViewCell or a subclass of it- No reuse identifier given:
registerClass needs { forCellWithReuseIdentifier } - The reuse identifier is an empty string:
registerClass needs a non-empty forCellWithReuseIdentifier
Examples
js
const list = new UICollectionView(
UICollectionViewCompositionalLayout.layoutWithListConfiguration(
new UICollectionLayoutListConfiguration('insetGrouped')));
list.registerClass(UICollectionViewListCell, { forCellWithReuseIdentifier: 'row' });Effect: afterwards, cellProvider can get a UICollectionViewListCell with 'row'.
Corresponding iOS API
-[UICollectionView registerClass:forCellWithReuseIdentifier:]. ObjC writes UICollectionViewListCell.class; JS writes the class name directly.