我的Xcode项目中有一个单元格
let head="headerid"
collectionView?.register(UICollectionViewCell.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: head)
override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
let aheader=collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: head, for: indexPath )
aheader.backgroundColor = .orange
return aheader
}
当我尝试运行此文件时,它会给我一个错误
'could not dequeue a view of kind: UICollectionElementKindSectionFooter with identifier headerid - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
即使其他单元格(不是forSupplementaryViewOfKind
)正在使用此代码