簡體   English   中英

在 Swift 4.2 中 NSCollectionView 的 SupplementaryElementKind 字符串值中使用什么

[英]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.SupplementaryElementKindenum 文檔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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM