私は2つの別々のView Controllerを持っています。
にはViewController1
、CollectionView1
正常に動作する と セルがあります。storyboard
withを使用してセルをセットアップしましたReuseIdentifier "Cell1"
。
にはViewController2
、CollectionView2
正常に動作する別のセルがあります。storyboard
withも使用してセルをセットアップしましたReuseIdentifier "Cell2"
。
両方のセルにはカスタム セル クラスがあり、UserCell1
とUserCell2
、および は、個別の 内で正常に動作しますCollectionViews
。
の 2 番目のセルにはCollectionView2
、最初のコレクション ビューのセルを使用します(ie. IndexPath(row: 1, section: 0))
。
ではCollectionView2
、次のものが必要です。
IndexPath(row: 0, section: 0) -> "Cell1"
IndexPath(row: 1, section: 0) -> "Cell2"
でViewController2
、 内で、各 でcellForItemAt
どのセルに移動するかを示す数式を使用してみました。ただし、最初のセルは登録されていないと言っています...しかし、同じセルがそのホーム内で機能しているため、明らかに機能しています。dequeue
index
ViewController
CollectionView
ReuseIdentifier
内部cellForItemAt (numberOfRowsInSection = 2):
if indexPath == IndexPath(row: 0, section: 0) {
guard let cell1 = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell1", for: indexPath) as? UserCell1 else { return UICollectionViewCell() }
cell1.configure(user: selectedUser)
return cell1
} else if indexPath == IndexPath(row: 1, section: 0) {
guard let cell2 = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell2", for: indexPath) as? UserCell2 else { return UICollectionViewCell() }
cell2.configure(user: selectedUser)
return cell2
} else {
return UICollectionViewCell()
}
私が得ているエラーは次のとおりです。
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'could not dequeue a view of kind: UICollectionElementKindCell with identifier Cell1 - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
前もって感謝します!!!!これは私を夢中にさせています:(