开发者

How to retrieve NSCollectionViewItems from a NSCollectionView

I just implemented an NSCollectionView just like the one described on the developer page and it work perfec开发者_如何学JAVAtly.

Now, how can I access to collectionViewItems from CollectionView?


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+.


Swift 5.0

let allSections = self.collectionView.numberOfSections
      (0..<allSections).forEach { aSection in
        let items = self.collectionView.numberOfItems(inSection: aSection)
        (0..<items).forEach { item in
            let indexpath = IndexPath(item: item, section: aSection)
            if let item = self.collectionView.item(at: indexpath) {
                print(item)
            }
        }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜