gpt4 book ai didi

ios - 获取对 UIcollectionview 中特定单元格的引用

转载 作者:可可西里 更新时间:2023-11-01 06:23:03 24 4
gpt4 key购买 nike

我正在尝试获取对 Collection View 中第一个单元格的引用以便移动它(为了某种效果)。

首先,你能移动集合中的某个单元格吗?

其次,我如何检查它现在是否在可见矩形上? (细胞可重复使用)。

错误:当我这样做时,当我将索引路径设置为非零

时,我也会收到错误消息
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:4];//E
CGRect cellRect = cell.frame;
NSLog(@"%f",cellRect.origin.y);



}

“在 ARC 中不允许隐式转换 int”。

当它设置为 0 时,我总是得到 0 的位置,即使单元格在屏幕外也是如此。

我想我错过了获取第一个单元格的正确方法..

最佳答案

你应该创建一个 NSIndexPath 的实例来使用 cellForItemAtIndexPath

示例

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:4 inSection:0];
UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath];
CGRect cellRect = cell.frame;
}

关于ios - 获取对 UIcollectionview 中特定单元格的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25380631/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com