Click on NSCollectionView returns always the same object

184 views Asked by At

I' ve a NSCollectionViewItem subclass, called MyItem used as item of my NSCollectionView. I need to enumerate all the item in my collection view to set the delegate for each item with this code:

NSUInteger categoryNumber = [self.collectionView.content count];

for (NSUInteger cont = 0;cont < categoryNumber;cont++)
{

    MyItem *categoryItem = (MyItem*)[self.collectionView itemAtIndex:cont];

    categoryItem.interactionDelegate = self;

}

Using the debugger I saw that this code works as I aspect and in each iteration the MyItem points to a different object each time. The problem is that when I use mouseDown event on my MyItem class I receive the same object whatever item i click on the NSCollectionView. It seems that the collection view use only one class (the cell template instance?). Anyone have an idea of what is going on? thanks

1

There are 1 answers

0
Luca On

The problem is in another part of my code and the NSCOllectionView returns, obviously, the correct object each time.