大佬教程收集整理的这篇文章主要介绍了ios – 有没有办法确定self.collectionview.visiblecells的顺序?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
UICollectionViewCell *cell = [self.collectionView.visibleCells firstObject];
从collectionView中的所有项返回第一项
UICollectionViewCell *cell = [self.collectionView cellForItemATindexPath:[NSIndexPath indexPathForItem:0 inSection:0]];
你不想要单元格,只需要数据:
NSIndexPath *indexPath = [[self.collectionView indexPathsForVisibleItems] firstObject]; id yourData = self.datasource[indexPath.row];
但visivleCells阵列没有订购!
那么,你需要订购它:
NSArray *indexPaths = [self.collectionView indexPathsForVisibleItems]; NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:@"row" ascending:YES]; NSArray *orderedIndexPaths = [indexPaths sortedArrayUsingDescriptors:@[sort]]; // orderedIndexPaths[0] would return the position of the first cell. // you can get a cell with it or the data from your datasource by accessing .row
编辑:我相信visibleCells(和类似)已经返回订单,但我没有在文档上找到任何相关的内容.所以我添加了订购部分只是为了确保.
以上是大佬教程为你收集整理的ios – 有没有办法确定self.collectionview.visiblecells的顺序?全部内容,希望文章能够帮你解决ios – 有没有办法确定self.collectionview.visiblecells的顺序?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。