HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 有没有办法确定self.collectionview.visiblecells的顺序?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在集合视图中,我想知道在集合视图中显示的第一个项目.我想我会看看visibleCells并且会成为列表中的第一个项目,但事实并非如此.

解决方法

@H_403_10@ 返回collectionView上可见的第一个项目:

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,请注明来意。