开发者

How to retrieve NSCollectionViewItems from a NSCollectionView

开发者 https://www.devze.com 2023-03-15 19:05 出处:网络
I just implemented an NSCollectionView just like the one described on the developer page and it work perfec开发者_如何学JAVAtly.

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

精彩评论

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

关注公众号