0
我創建了一個簡單的collectionView,並設置單元格顯示每個單元格單擊時要顯示的屏幕預覽。這一切工作正常,所以我正在向每個部分添加標題。Swift 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
}
}
}
一切編譯罰款,但顯示出來完全空白。
有什麼想法?
閱讀蘋果文檔,好像你必須重寫此'UICollectionViewLayout'方法:'layoutAttributesForSupplementaryViewOfKind:atIndexPath:'。我認爲該方法應該返回:'.SupplementaryView' – alaphao