10.11 NSCollectionView:"could not load the nibName: NSCollectionViewItem in bundle NSBundle"

10.11 NSCollectionView: "could not load the nibName: NSCollectionViewItem in bundle NSBundle"

根据 https://developer.apple.com/library/mac/releasenotes/AppKit/RN-AppKit/#10_11CollectionView,我想将 NSCollectionView 与来自 Swift 的新 API 模型一起使用。因为我更喜欢在 IB 中做尽可能多的事情,所以我想使用内容绑定并遵循链接页面上的 将内容绑定到 NSCollectionView(自 WWDC 种子以来新增) 部分。

我已经从对象库中将一个 NSCollectionView 拉到我的故事板中,然后通过连接检查器删除了额外生成的 prototype segue,还删除了生成的 NSCollectionViewItem。然后,我将集合视图的布局设置为 Flow,并将集合视图连接到我的视图控制器的出口。

接下来,我使用 Xcode 的视图模板创建了一个单独的 .xib 文件,并放入了必要的视图。我还引入了一个 "Collection View Item" 对象。

然后,我调整了视图控制器的 viewDidLoad 方法以将笔尖注册到集合视图。

override func viewDidLoad() {
    super.viewDidLoad()

    let nib = NSNib(nibNamed: "Item", bundle: nil)!
    collectionView.registerNib(nib, forItemWithIdentifier: "")
}

最后,我将数组控制器连接到 NSCollectionView 的内容绑定。

但是,当我尝试启动该应用程序时,出现异常:

[NSNib _initWithNibNamed:bundle:options:] could not load the nibName: NSCollectionViewItem in bundle NSBundle

仅当我的数组具有实际内容时才会发生异常,因此仅当需要实例化 CollectionViewItems 时才会发生。

我做错了什么?

示例项目在这里:https://scriptreactor.com/collectionviewtest.zip

问题在于,在 Collection View Item 的 .xib 中,Item 对象 的视图出口需要链接到根视图。此外,需要在 Item 对象.

的属性检查器中设置 Nib 名称