When you drag a NSCollectionView to a view, a NSCollectionViewItem appears on the storyboard, floating around.
Imagine I drag several NScollectionViews to the same view. I will have a bunch of NSCollectionViewItems. How a collection view knows which NScollectionViewItem belongs to it? Is there a connection between the two that can be seen on interface builder? I don't see anything on interface builder? Where to do I see that?
EDIT: Apparently this seems to be a Xcode bug. When you add a NSCollectionView to the storyboard, it comes without a link to the NSCollectionViewItem and it seems to be impossible to connect the itemPrototype outlet between them.
After contacting Apple about bugs like this, their answer was: "this is a know issue with Storyboards on OS X. Use Xibs instead."
The NSCollectionViewItem class defines the visual appearance of items in the collection view. Your data source object vends items from its collectionView (_:itemForRepresentedObjectAt:) method, creating and configuring the item in one step. Each item is essentially a snapshot of the data it represents.
You can add collection views to your interface using Interface Builder or create them programmatically in your view controller or window controller code. It is recommended that you configure your collection view with a data source object, which is an object that conforms to the NSCollectionViewDataSource protocol.
The collection view obtains the views for items and supplementary views from its data source, which creates the views and fills them with data. The layout object provides the layout attributes needed to position those items and supplementary views onscreen.
An ordered collection of data items displayed in a customizable layout. The simplest type of collection view displays its items in a grid, but you can define layouts to arrange items however you like. For example, you might create a layout where items are arranged in a circle.
Well, I gave @RubberDuck's workaround a go but it didn't work (see my comment). What worked for me is setting collectionView.itemPrototype
in viewDidLoad
of the view controller (Xcode 6.1):
@IBOutlet weak var collectionView: NSCollectionView! override func viewDidLoad() { // don't forget to set identifier of CollectionViewItem // from interface builder let itemPrototype = self.storyboard?.instantiateControllerWithIdentifier("collectionViewItem") as NSCollectionViewItem self.collectionView.itemPrototype = itemPrototype }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With