[iOS/Error] UICollectionView Header로 UICollectionReusableView를 사용할 때 Xib, 뷰가 보이지 않는 경우

김혜수·2022년 6월 30일
0

UICollectionReuasbleView not showing
UICollectionView Section Header not showing

문제

사용한 UICollectionReusableView는
StickerDetailFeedHeaderCollectionReusableView.xib
StickerDetailFeedHeaderCollectionReusableView.swift 입니다.
Identifier도 StickerDetailFeedHeaderCollectionReusableView

collectionView.register(StickerDetailFeedHeaderCollectionReusableView.self,
                                forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader,
                                withReuseIdentifier: Const.Identifier.StickerDetailFeedHeaderCollectionReusableView)

dataSource.supplementaryViewProvider = { (collectionView, kind, indexPath) -> UICollectionReusableView in
            
                guard let header = collectionView.dequeueReusableSupplementaryView(
                    ofKind: UICollectionView.elementKindSectionHeader,
                    withReuseIdentifier: Const.Identifier.StickerDetailFeedHeaderCollectionReusableView,
                    for: indexPath) as? StickerDetailFeedHeaderCollectionReusableView else {
                        return UICollectionReusableView() }
                return header
            }

해결


collectionView.register(UINib(nibName: Const.Identifier.StickerDetailFeedHeaderCollectionReusableView,
                                      bundle: nil),
                                forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader,
                                withReuseIdentifier: Const.Identifier.StickerDetailFeedHeaderCollectionReusableView)

register할 때 class에서 UINIb로 바꿔주니 잘 보였다

profile
iOS를 좋아하는 사람

0개의 댓글