objective-ccocoacocoa-bindings

How to retrieve NSCollectionViewItems from a NSCollectionView


I just implemented an NSCollectionView just like the one described on the developer page and it work perfectly.

Now, how can I access to collectionViewItems from CollectionView?


Solution

  • If you really need to enumerate all items in a collection view, then:

    NSUInteger numberOfItems = [[collectionView content] count];
    for (NSUInteger itemIndex = 0; itemIndex < numberOfItems; itemIndex++) {
        NSCollectionViewItem *item = [collectionView itemAtIndex:itemIndex];
        // do something with item
    }
    

    should do the trick on Mac OS X v10.6+.