我在这里使用自定义集合视图流布局,并且使用xib成功加载了单元格,而使用xib加载标头时却崩溃了,谁能帮助我这是怎么回事?
这是我的视图加载了代码
let cellNib = UINib(nibName: "searchHistoryCollectionViewCell", bundle: nil)
self.searchCollectionView.register(cellNib, forCellWithReuseIdentifier: "hotSearchCell")
let headerNib = UINib(nibName: "searchSectionHeaderCollectionReusableView", bundle: nil)
self.searchCollectionView.register(headerNib, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "searchHeader")
这是我的收藏夹视图头代码
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
return CGSize(width: collectionView.frame.width, height: 50) //add your height here
}
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
if indexPath.section == 0 {
let header = searchCollectionView.dequeueReusableSupplementaryView(ofKind:UICollectionElementKindSectionHeader, withReuseIdentifier: "searchHeader", for: indexPath) as! searchSectionHeaderCollectionReusableView
header.backgroundColor = #colorLiteral(red: 0.9578801208, green: 0.9578801208, blue: 0.9578801208, alpha: 1)
header.hotSearchLabel.text = " Hot Search"
header.deleteButton.isHidden = true
return header
}
else {
let header = searchCollectionView.dequeueReusableSupplementaryView(ofKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "searchHeader", for: indexPath) as! searchSectionHeaderCollectionReusableView
header.backgroundColor = #colorLiteral(red: 0.9578801208, green: 0.9578801208, blue: 0.9578801208, alpha: 1)
header.hotSearchLabel.text = " Search History"
header.deleteButton.isHidden = false
header.deleteButton.addTarget(self, action: #selector(clearHistoryData), for: .touchUpInside)
return header
}
}
这是我的xib图像
*由于未捕获的异常而终止应用程序 “ NSInternalInconsistencyException”,原因:“无法在其中加载NIB 捆绑包:'NSBundle /Users/ewall-mac-2/Library/Developer/CoreSimulator/Devices/1DF7324A-FFEA-47B7-B6C3-C03A09B80B7B/data/Containers/Bundle/Application/B1132E40-14E6-421C-BBCE-3BE142C82CFB/My.app(已加载)',名称为“ searchSectionHeaderCollectionReusableView” * 首先抛出调用堆栈: