【问题标题】:Logging Cell in CollectionViewCollectionView 中的日志记录单元
【发布时间】:2013-04-30 15:36:44
【问题描述】:

我有一个全屏collectionView的视图,它的单元格也是全屏的;一次可以查看一个单元格(让我们假设它是 iPhone 5 只是为了简单起见)。在下面的代码中,我正在记录加载了哪个单元格:

- (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 垂直滚动),index:0 移动到1。当我向上滚动同一个像素时,它仍然显示1。显然,向下滚动该像素仅显示第二个单元格的一个像素,该像素已被记录。向上滚动显示整个第一个单元格,但不记录 0

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

【问题讨论】:

    标签: iphone uitableview nsarray uicollectionview uicollectionviewcell


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-29
      相关资源
      最近更新 更多