4

iOS15とUIKitのいくつかの新機能をテストしています。いくつかの問題に遭遇しましたが、それらを解決する方法がわかりません。私はそのコードを変更しませんでした。これは、iOS 14 で完全に機能するコードの一部ですが、ターゲットを更新した後、エラーがスローされます。

Xcodeは、タイプUICollectionElementKindSectionHeaderUICollectionViewのカスタム ヘッダーがdataSourceに返される瞬間にクラッシュします。これが私のコードです:

private func configureDataSource() {
      dataSource = UICollectionViewDiffableDataSource<Section, Follower>(collectionView: collectionView, cellProvider: { (collectionView, indexPath, followers) -> UICollectionViewCell? in
         let cell = collectionView.dequeueReusableCell(withReuseIdentifier: FollowerCell.reuseId, for: indexPath) as! FollowerCell
         cell.set(on: followers)
         return cell
      })
      
      dataSource.supplementaryViewProvider = { (collectionView, kind, indexPath) in
         let header = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader,
                                                                      withReuseIdentifier: FollowersCollectionHeaderView.reuseId,
                                                                      for: indexPath) as! FollowersCollectionHeaderView
         
         header.set(with: self.user)
         return header
      }
   }

ログには次のように記載されています。

-collectionView:viewForSupplementaryElementOfKind:atIndexPath: から返されたビューは、使用されている要素の種類と一致しません。要素の種類 'FollowersCollectionHeaderView' のビューを要求されると、データ ソースは要素の種類 'UICollectionElementKindSectionHeader' に登録されたビューをキューから取り出しました。

UICollectionElementKindSectionHeaderFollowersCollectionHeaderViewにキャストしたため、ここで何が問題なのかわかりません。

WWDC21の UIKit の新機能を見てきましたが、その特定のコードの変更について言及されていません。

そのコードで何を修正すればよいですか?

4

1 に答える 1