首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在SWIFT4.2中NSCollectionView的SupplementaryElementKind字符串值中使用什么

在SWIFT4.2中NSCollectionView的SupplementaryElementKind字符串值中使用什么
EN

Stack Overflow用户
提问于 2018-10-18 05:48:57
回答 1查看 364关注 0票数 2

在SWIFT4.2之前,我可以创建一个NSCollectionView头,如下所示:

代码语言:javascript
复制
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.SupplementaryElementKindString

这就留给我更新的SWIFT4.2代码,如下所示:

代码语言:javascript
复制
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文件中,我没有看到任何与它相关联的东西。

EN

回答 1

Stack Overflow用户

发布于 2018-10-18 19:49:10

我想通了。您只需从它所在的kind委托方法中传入makeSupplementaryView参数。

代码语言:javascript
复制
let view = collectionView.makeSupplementaryView(ofKind: kind, withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "Header"), for: indexPath as IndexPath) as! Header
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52867739

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档