Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cocoa - Where is the link between a NSCollectionView and a NSCollectionViewItem? Xcode 6 Bug?

Tags:

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."

like image 908
Duck Avatar asked Oct 24 '14 06:10

Duck


People also ask

What is the nscollectionviewitem class?

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.

How do I add a collection view to an interface?

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.

What is the difference between a collection view and layout object?

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.

What is an ordered collection view?

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.


1 Answers

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 } 
like image 55
mostruash Avatar answered Dec 08 '22 09:12

mostruash