ios – 有没有办法确定self.collectionview.visiblecells的顺序?

ios – 有没有办法确定self.collectionview.visiblecells的顺序?,第1张

概述在集合视图中,我想知道在集合视图中显示的第一个项目.我想我会看看visibleCells并且会成为列表中的第一个项目,但事实并非如此. 返回collectionView上可见的第一个项目: UICollectionViewCell *cell = [self.collectionView.visibleCells firstObject]; 从collectionView中的所有项返回第一项 UI 在集合视图中,我想知道在集合视图中显示的第一个项目.我想我会看看visibleCells并且会成为列表中的第一个项目,但事实并非如此.解决方法 返回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的顺序?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1005688.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-22
下一篇2022-05-22

发表评论

登录后才能评论

评论列表(0条)

    保存