作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 Swift 4.2 之前,我可以创建一个 NSCollectionView
header ,如下所示:
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
。但是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 文件中没有看到任何其他与它相关联的内容。
最佳答案
我明白了。您只需从其内部的 makeSupplementaryView
委托(delegate)方法传入 kind
参数即可。
let view = collectionView.makeSupplementaryView(ofKind: kind, withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "Header"), for: indexPath as IndexPath) as! Header
关于cocoa - Swift 4.2 中 NSCollectionView 的 SupplementaryElementKind 字符串值中使用什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52867739/
在 Swift 4.2 之前,我可以创建一个 NSCollectionView header ,如下所示: func collectionView(_ collectionView: NSCollec
我是一名优秀的程序员,十分优秀!