0

I have looked at the NSCollectionView API and I havnt found anything matching certain tutorials I have seen. Xcode forces me to write my method like this so that there are no errors:

@objc(collectionView:didSelectItemsAtIndexPaths:) func collectionView(_ collectionView: NSCollectionView, didSelectItemsAt indexPaths: Set<IndexPath>) {
    print("Selected")
}

Whenever I click on an item in my NSCollectionView nothing happens and my print statement never shows in the console. What is the correct way to select an item from a NSCollectionView?

  • Have you set the collectionView's delegate? – Michael Oct 10 '16 at 22:36
  • Yes I have it set in extension ViewController: NSCollectionViewDelegate and it still doesn't print anything to the console. – Nick Balistreri Oct 10 '16 at 22:46
  • I'd be inclined to put a `print` in the code after setting the delegate, as the most likely cause is that it's not actually set. I wouldn't expect you'd have to put the `@objc` part in either - what error are you getting without it? It might be helpful if you include all the relevant parts of your code. – Michael Oct 11 '16 at 00:26
  • I got it to work without the @obj part in front of it but it is still not printing "Selected" in the console whenever I click on an item. What could possibly be the reason for this. This is really holding me back for something that would seem so simple. – Nick Balistreri Oct 11 '16 at 15:02
  • I am dumb...I didn't drag my collectionViewDelegate to connect to my ViewController. I am new to xCode and having to do all this dragging to set stuff up throws me off sometimes. – Nick Balistreri Oct 11 '16 at 15:15

1 Answers1

0

You should set the property isSelectAble = true,like this:

self.collectionView. isSelectAble = true
Lung
  • 11
  • 3