【发布时间】:2018-10-18 05:48:57
【问题描述】:
在 Swift 4.2 之前,我可以像这样创建一个 NSCollectionView 标头:
func collectionView(_ collectionView: NSCollectionView, viewForSupplementaryElementOfKind kind: NSCollectionView.SupplementaryElementKind, at indexPath: IndexPath) -> NSView {
let view = collectionView.makeSupplementaryView(ofKind: .sectionHeader, withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "Header"), for: indexPath as IndexPath) as! Header
view.sectionTitle.stringValue = collectionSections[indexPath.section]
return view
}
如果我没记错的话,.sectionHeader 来自enum,来自NSCollectionView.SupplementaryElementKind。但是the docs 说NSCollectionView.SupplementaryElementKind 是String。
这给我留下了更新的 Swift 4.2 代码,如下所示:
func collectionView(_ collectionView: NSCollectionView, viewForSupplementaryElementOfKind kind: NSCollectionView.SupplementaryElementKind, at indexPath: IndexPath) -> NSView {
let view = collectionView.makeSupplementaryView(ofKind: "?????", withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "Header"), for: indexPath as IndexPath) as! Header
view.sectionTitle.stringValue = collectionSections[indexPath.section]
return view
}
我不清楚我应该为 ofKind 参数 (String) 添加什么内容。该字符串对应于什么?我在我的 xib 文件中看不到任何其他可以与之关联的内容。
【问题讨论】:
标签: cocoa nscollectionview swift4.2