macoscocoaselectionnscollectionviewnscollectionviewitem

NSCollectionView selection and deselection


I recently got my NSCollectionView worked in the way, that it handles section the right way. I reached this by adding a binding with the Model Key Path "selected". This action hides a blue view, that shows a selection to the user. The Problem is, that i can't deselect my NSCollectionViewItem by clicking outside the image in the view, which is lowest view in the hierarchy of my NSCollectionViewItem. It also didn't deselect the itemView when I'm clicking out of my CollectionView. I tried to get it worked by subclassing my NSCollectionItemView and overriding the selected variable. But, as I said, till now I haven't reached anything to solve my Problem.

Now I'm hoping for help. What can I do?

PS: I did setup the NSControllerView with an arrayController through my MainStoryboard. And Yeah... I just started to programming with swift and cocoa for OS X. But I got some knowledge of cocoa touch. Is there any familiar way to initialise and handle actions of a NSCollectionView like an UICollectionView?


Solution

  • Apple has a WWDC session in 2015 talking about What's New in NSCollectionView with the new API. It talks about Selection at 36'33".

    The Objective-C Sample Code CocoaSlideCollection shows the selection code in action.

    I created a video tutorial on Selection as well, Sample code is available here.