![](/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.