добавить пользовательский заголовок в коллекцию Swift

Я пытаюсь добавить заголовок к collectionView, используя пользовательский файл xib. Я создал файл xib с классом, реализующим UICollectionReusableView. В collectionViewController я зарегистрировал файл xib следующим образом:

self.collectionView.register(UINib(nibName: HCollectionReusableView.nibName, bundle: nil), forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: HCollectionReusableView.reuseIdentifier)

, а после этого в viewForSupplementaryElementOfKind я сделал

let header = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionElementKindSectionHeader, withReuseIdentifier: HCollectionReusableView.reuseIdentifier, for: indexPath) as! HCollectionReusableView

и для калибровки

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
    return CGSize(width: 100, height: 50)
}

Я получаю сообщение об ошибке: не удалось загрузить NIB в комплекте. какой-нибудь недостающий код?

Класс HCollectionReusableView:

class HCollectionReusableView: UICollectionReusableView {

static var nibName : String
    {
    get { return "headerNIB"}
}

static var reuseIdentifier: String
    {
    get { return "headerCell"}
}



override func awakeFromNib() {
    super.awakeFromNib()
    // Initialization code
}

}

8
задан Jack 16 October 2017 в 12:03
поделиться