NSCollectionView 似乎不需要注册它的项目 class
NSCollectionView doesn't seem to need registering its item class
当我制作NSCollectionView时UI...
第一次,我使用
注册了我的 collection 查看项目 class
self.cv.register(NSNib.init(nibNamed: "ContentItemOneClass", bundle: nil), forItemWithIdentifier: "ContentItemOneClass")
而且我添加了更多 collection 观看次数,忘记像
一样打电话
self.cv.register(NSNib.init(nibNamed: "ContentItemTwoClass", bundle: nil), forItemWithIdentifier: "ContentItemTwoClass")
但是 collectionView(_:itemForRepresentedObjectAt:)
, makeItem(withIdentifier:"ContentItemTwoClass", for: indexPath)
似乎工作得很好。
现在我想知道是否需要注册 classes 或是否可以删除。
谢谢。
Apple 有一个名为 CocoaSlideCollection
的示例应用程序,它演示了现代(即 10.11+)NSCollectionView
的使用。在文件AAPLBrowserWindowController.m
中的collectionView:itemForRepresentedObjectAtIndexPath:
方法中,有这样的注释:
Message back to the collectionView, asking it to make a @"Slide" item associated with the given item indexPath. The collectionView will first check whether an NSNib or item Class has been registered with that name (via -registerNib:forItemWithIdentifier: or -registerClass:forItemWithIdentifier:). Failing that, the collectionView will search for a .nib file named "Slide". Since our .nib file is named "Slide.nib", no registration is necessary.
虽然我没有看到文档中明确提到这一点,但这表明只要 .xib
名称与标识符匹配(并且只有一个 NSCollectionViewItem
或 in 的子类文件),则不需要注册。
当我制作NSCollectionView时UI...
第一次,我使用
注册了我的 collection 查看项目 classself.cv.register(NSNib.init(nibNamed: "ContentItemOneClass", bundle: nil), forItemWithIdentifier: "ContentItemOneClass")
而且我添加了更多 collection 观看次数,忘记像
一样打电话self.cv.register(NSNib.init(nibNamed: "ContentItemTwoClass", bundle: nil), forItemWithIdentifier: "ContentItemTwoClass")
但是 collectionView(_:itemForRepresentedObjectAt:)
, makeItem(withIdentifier:"ContentItemTwoClass", for: indexPath)
似乎工作得很好。
现在我想知道是否需要注册 classes 或是否可以删除。
谢谢。
Apple 有一个名为 CocoaSlideCollection
的示例应用程序,它演示了现代(即 10.11+)NSCollectionView
的使用。在文件AAPLBrowserWindowController.m
中的collectionView:itemForRepresentedObjectAtIndexPath:
方法中,有这样的注释:
Message back to the collectionView, asking it to make a @"Slide" item associated with the given item indexPath. The collectionView will first check whether an NSNib or item Class has been registered with that name (via -registerNib:forItemWithIdentifier: or -registerClass:forItemWithIdentifier:). Failing that, the collectionView will search for a .nib file named "Slide". Since our .nib file is named "Slide.nib", no registration is necessary.
虽然我没有看到文档中明确提到这一点,但这表明只要 .xib
名称与标识符匹配(并且只有一个 NSCollectionViewItem
或 in 的子类文件),则不需要注册。