最初にsectionHeaderをコレクションビューに追加すると、正常に表示されました。私はcollectionViewController.swiftにこれを持ち、ヘッダーのクラスを持っていました。CollectionViewセクションヘッダーが表示されない
override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
let header = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "header", for: indexPath) as! HomeHeader
return header
}
これをviewDidLoad()
に追加すると、ヘッダーは表示されなくなります。
let cellsAcross: CGFloat = 2
let spaceBetweenCells: CGFloat = 5
let dimX = ((collectionView?.bounds.width)! - (cellsAcross - 1) * spaceBetweenCells)/cellsAcross
let dimY = CGFloat(dimX/187 * 125)
let cellSize = CGSize(width: dimX , height: dimY)
let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .vertical
layout.itemSize = cellSize
//layout.sectionInset = UIEdgeInsets(top: 1, left: 1, bottom: 1, right: 1)
layout.minimumLineSpacing = 5.0
layout.minimumInteritemSpacing = 5.0
collectionView?.setCollectionViewLayout(layout, animated: true)
collectionView?.reloadData()
これは、すべての画面サイズで2行のセルを表示するように強制しています。 (私はまだセル内のすべてのコンテンツのサイズを変更しないという問題があります)。
私は、ヘッダはもはや
を見える理由はわからないんあなたは、ヘッダーの高さメソッドを実装必要