带标识符headerid的UICollectionElementKindSectionFooter - 必须为标识符注册一个nib或类

时间:2017-01-21 15:18:34

标签: ios swift

我的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)正在使用此代码

0 个答案:

没有答案