![](/img/trans.png)
[英]Binding to both the checked state and string value of NSCheckBoxes in an NSCollectionView
[英]What to Use in NSCollectionView's SupplementaryElementKind String Value in Swift 4.2
在 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
來自NSCollectionView.SupplementaryElementKind
的enum
。 但文檔說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 文件中看不到任何其他相關聯的內容。
我想到了。 您只需從makeSupplementaryView
在的makeSupplementaryView
委托方法傳入kind
參數。
let view = collectionView.makeSupplementaryView(ofKind: kind, withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "Header"), for: indexPath as IndexPath) as! Header
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.