0

私は2つの別々のView Controllerを持っています。

にはViewController1CollectionView1正常に動作する と セルがあります。storyboardwithを使用してセルをセットアップしましたReuseIdentifier "Cell1"

にはViewController2CollectionView2正常に動作する別のセルがあります。storyboardwithも使用してセルをセットアップしましたReuseIdentifier "Cell2"

両方のセルにはカスタム セル クラスがあり、UserCell1UserCell2、および は、個別の 内で正常に動作しますCollectionViews

の 2 番目のセルにはCollectionView2、最初のコレクション ビューのセルを使用します(ie. IndexPath(row: 1, section: 0))

ではCollectionView2、次のものが必要です。

IndexPath(row: 0, section: 0) -> "Cell1"
IndexPath(row: 1, section: 0) -> "Cell2"

ViewController2、 内で、各 でcellForItemAtどのセルに移動するかを示す数式を使用してみました。ただし、最初のセルは登録されていないと言っています...しかし、同じセルがそのホーム内で機能しているため、明らかに機能しています。dequeueindexViewControllerCollectionViewReuseIdentifier

内部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'

前もって感謝します!!!!これは私を夢中にさせています:(

4

2 に答える 2