UICollectionViewDataSource
#UICollectionView
register
Cell なら registerClass:forCellWithReuseIdentifier: とか registerNib:forCellWithReuseIdentifier: とか、Supplementary View なら registerClass:forSupplementaryViewOfKind:withReuseIdentifier: とか registerNib:forSupplementaryViewOfKind:withReuseIdentifier: とかを使う。
Collection View Programming Guide for iOS - Registering Your Cells and Supplementary Views
dequeue
UICollectionViewDataSource は、CollectionView から問い合わせが当たっ時に、Cell や Supplementary view を提供する責務を持つ。これを達成するメソッドが collectionView(_:cellForItemAt:) と collectionView(_:viewForSupplementaryElementOfKind:at:) の2つ。前者は必須だが、後者は Supplementary View の場合に利用する任意のメソッド。
このメソッドでやる処理は以下。
1. 適切なタイプの View もしくは Cell を deque する
dequeueReusableCell(withReuseIdentifier:for:) や dequeueReusableSupplementaryView(ofKind:withReuseIdentifier:for:) を利用する
再利用可能なものがなければ、nib, Storyboard からロード、あるいは initWithFrame: でインスタンスが作られる
Cell, View に以前のデータが残っている場合、prepareForReuse によってそれをリセットする機会が与えられる
カスタム Cell, View を作成するときは、このメソッドをオーバーライドして、プロパティをデフォルト値にリセットする必要がある
2. 特定の IndexPath のデータを利用して View を設定する
indexPath から適切なデータを見つけ、それを View に反映、ということをする
3. View を返す
Dequeueing and Configuring Cells and Views - Collection View Programming Guide for iOS