繁体   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