Что использовать в строковом значении SupplementaryElementKind NSCollectionView в Swift 4.2 - PullRequest
0 голосов
/ 18 октября 2018

До 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 был из enum изNSCollectionView.SupplementaryElementKind.Но документы говорят 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.

1 Ответ

0 голосов
/ 18 октября 2018

Я понял это.Вы просто передаете параметр kind из метода делегата makeSupplementaryView, в котором он находится.

let view = collectionView.makeSupplementaryView(ofKind: kind, withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "Header"), for: indexPath as IndexPath) as! Header
...