我已经声明了如下收集视图
lazy var collectionView:UICollectionView = {
let layout = UICollectionViewFlowLayout()
layout.itemSize = UICollectionViewFlowLayout.automaticSize
layout.minimumLineSpacing = 52
layout.sectionInset = UIEdgeInsets(top: 25, left: 0, bottom: 30, right: 0)
var collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
collectionView.backgroundColor = UIColor.white
collectionView.showsVerticalScrollIndicator = false
collectionView.register(XXXCollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)
collectionView.register(XXXHeaderViewCell.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: headerIdentifier)
collectionView.delegate = self
return collectionView
}()
并且在委托下实现,控制仅用于referenceSizeForHeaderInSection方法,而未用于viewForSupplementaryElementOfKind
public func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: headerIdentifier, for: indexPath)
return headerView
}
public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
let size = CGSize(width: self.collectionView.bounds.width, height: 200)
return size
}
任何帮助都非常感谢。
最佳答案
我在这里有同样的问题:func collectionView(_ collectionView: UICollectionView, willDisplaySupplementaryView view: UICollectionReusableView, forElementKind elementKind: String, at indexPath: IndexPath) -> UICollectionReusableView { guard let flexLegendCell = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "flexLegendCell", for: indexPath) as? FlightsFlexReturnLegendCellView else { return UICollectionViewCell(frame: .zero) } flexLegendCell.frame.size.height = 100 return flexLegendCell }
但它从未
关于ios - viewForSupplementaryElementOfKind没有被调用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57208600/