Iphone CollectionView中的日志记录单元格

Iphone CollectionView中的日志记录单元格,iphone,uitableview,nsarray,uicollectionview,uicollectionviewcell,Iphone,Uitableview,Nsarray,Uicollectionview,Uicollectionviewcell,我有一个全屏集合视图,它的单元格也是全屏的;一次只能看到一个单元格(假设是iPhone5,只是为了简单起见)。在下面的代码中,我将记录加载的单元格: - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { CollectionViewCell *cell = [collectio

我有一个全屏集合视图,它的单元格也是全屏的;一次只能看到一个单元格(假设是iPhone5,只是为了简单起见)。在下面的代码中,我将记录加载的单元格:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
    {
        CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CollectionCell" forIndexPath:indexPath];
        NSObject *someObject = [someArray  objectAtIndex:indexPath.row];
        cell.someLabel.text = [someObject valueForKey:@"label"];

        NSLog(@"index:%d",[someArray indexOfObject:someObject]);
    }
当我向下滚动一个像素时(collectionView垂直滚动),
索引:
0
移动到
1
。当我向上滚动同一像素时,它的读数仍然是
1
。显然,向下滚动一个像素只显示记录的第二个单元格的一个像素。向上滚动显示整个第一个单元格,但不记录
0


如何记录当前完全在视图中的单元格?

试试这个。这可能对你有帮助

NSArray *arr = [collectionView indexPathsForVisibleItems];
if ([arr count]!=0) {
   NSLog(@"%@",[arr objectAtIndex:0]);
}