我有一个自定义的UICollectionReusableView,HeaderCollectionReusableView,我正在代码中使用它。而它又包含一个UILabel。当我使用标签时,由于某种原因,它是空的。我首先注册这个类,然后尝试使用出队来调用它。我遗漏了什么?
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
}发布于 2017-04-16 11:49:50
看一下代码,我假设定制的可重用视图不是使用xib创建的。最好的选择是
func register(_ nib: UINib?, forSupplementaryViewOfKind kind: String, withReuseIdentifier identifier: String))在viewDidLoad中注册
https://stackoverflow.com/questions/43433282
复制相似问题