単純な collectionView を作成し、各セルがクリックされたときに移動する画面のプレビューを表示するようにセルを設定しました。これはすべてうまくいったので、各セクションにヘッダーを追加する作業を進めています。
ただし、ここで問題が...
コードにセクションを追加すると、collectionView が消えました (または、少なくとも白い画面以外は何も表示されません)。
これが私が追加(または変更)したコードです。投稿されたコードが十分でない場合はお知らせください。さらに投稿します...
override func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {
let sectionHeaderView = collectionView.dequeueReusableSupplementaryViewOfKind(kind, withReuseIdentifier: "SectionHeader", forIndexPath: indexPath) as! SectionHeaderView
if let title = papersDataSource.titleForSectionAtIndexPath(indexPath) {
sectionHeaderView.title = title
}
return sectionHeaderView
}
override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return papersDataSource.numberOfSections
}
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return papersDataSource.numberOfPapersInSection(section)
}
そして、次のコードを持つ UICollectionReusableView のサブクラスを設定しました...
import UIKit
class SectionHeaderView: UICollectionReusableView {
@IBOutlet weak var titleLabel: UILabel!
var title: String? {
didSet {
titleLabel.text = title
}
}
}
すべてが正常にコンパイルされますが、完全に空白になります。
何かご意見は?