I have a NSCollectionView
and I am adding my custom view which acts as NSCollectionViewItem
for that collection view. In my collectionViewItem, I have a NSButton
along with various other elements. I have a method onButtonClick
which is connected to that button. Now, suppose I add 5 items of my collectonViewItem on to the collectionView.
How can I get the index of the view from where the button was clicked?
Inside onButtonClick
, I tried following code but it always returns 0 regardless of which button I click:
id collectionViewItem = [sender superView];
NSInteger index = [[colloectionView subviews] indexOfObject:collectionViewItem];
What is the right way to achieve this?