我工作得很好,有一个例外 . 部分 Headers 不会出现 . 应该出现的地方只是空地 . 下面代码中的最后一个 collectionView
函数,每次绘制 Headers 时都应调用,永远不会被调用 . 相反,它会抛出此警告:
实例方法'collectionView(:viewForSupplementaryElementOfKind:at :)'几乎匹配协议'NSCollectionViewDataSource'的可选要求'collectionView(:viewForSupplementaryElementOfKind:at :)'
有谁知道我做错了什么?如何让程序调用auxiliary-view-collectionView-function?
最好!
extension FacetWindow: NSCollectionViewDataSource{
func numberOfSections(in collectionView: NSCollectionView) -> Int {
return facets.count // how many sections?
}
func collectionView(_ collectionView: NSCollectionView, numberOfItemsInSection section: Int) -> Int {
return facets.facets[section].facetContent.count //how many items in section?
}
func collectionView(_ collectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -> NSCollectionViewItem {
let item = collectionView.makeItem(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "FacetsWindowCollectionViewItem"), for: indexPath)
guard let collectionViewItem = item as? FacetsWindowCollectionViewItem else {return item}
collectionViewItem.textField?.stringValue = facets[indexPath[0], indexPath[1]]
print("facet" , facets[indexPath[0], indexPath[1]])
return item
}
func collectionView(_ collectionView: NSCollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> NSView {
//this function never gets called!!!
let view = collectionView.makeSupplementaryView(ofKind: NSCollectionView.SupplementaryElementKind.sectionHeader, withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "FacetsWindowCollectionViewHeader"), for: indexPath) as! FacetsWindowCollectionViewHeader
view.FacetsWindowCollectionViewHeaderLabel.stringValue = facets[indexPath[0]]
return view
}
}