0
我在我的代码中使用了自定义的UICollectionReusableView,HeaderCollectionReusableView。而它又包含一个UILabel。当我去使用标签时,由于某种原因它是零。我首先注册了课程,然后我尝试用一个dequeue来调用它。我错过了什么?UICollectionReusableView内部的标签始终为零
override func viewDidLoad(){
super.viewDidLoad()
collectionView?.register(HeaderCollectionReusableView.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: colReusableViewIdentifier)
self.collectionView?.collectionViewLayout = UICollectionViewFlowLayout()
}
@objc override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
let headerReusableView = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionElementKindSectionHeader, withReuseIdentifier: colReusableViewIdentifier, for: indexPath) as! HeaderCollectionReusableView
headerReusableView.headerLabel.text = "Reacshn"
return headerReusableView
}
它结束了明确登记HeaderCollectionReusableView是导致无标签的问题。在我的情况下,简单地清理项目和重建没有注册电话工作。 –