Reputation: 67852
Here's how I create the collection view item:
func collectionView(collectionView: NSCollectionView, itemForRepresentedObjectAtIndexPath indexPath: NSIndexPath) -> NSCollectionViewItem {
let item = collectionView.makeItemWithIdentifier("ViewItem", forIndexPath: indexPath)
guard let collectionViewItem = item as? ViewItem else {
return item
}
return collectionViewItem
}
If I don't register the custom class ViewItem, selection works! As expected, IBOutlets are nil and I can't modify the object.
Before reloadData
in viewDidLoad
, if I use self.collectionView.registerClass(ViewItem.self, forItemWithIdentifier: "ViewItem")
, then IBOutlets are wired, and I can change the object, but no selection seems to work.
func collectionView(collectionView: NSCollectionView, didSelectItemsAtIndexPaths indexPaths: Set<NSIndexPath>) {
print("Select")
}
Never gets called. ViewItem is a xib with base class NSCollectionViewItem
. It has a single label (for now, to test this to get it working), and I've changed no default options.
What am I missing?
Upvotes: 2
Views: 638