【问题标题】:Second section in collection view not showing集合视图中的第二部分未显示
【发布时间】:2014-07-15 14:05:37
【问题描述】:

我有两个数组:

  • feedbackImages - UIImages 数组
  • feedbackVideos - 一个字典数组,其中包含两个键,视频 url 和缩略图。

我遇到的问题是第二部分(反馈视频)的所有单元格都没有显示。我目前正在为每个单元格使用一个图像来尝试让它工作。

当记录数组的计数时,它们都显示它们中有项目。

这是我的收藏视图代码:

#pragma mark - Collection View

- (NSInteger)numberOfSectionsInCollectionView: (UICollectionView *)collectionView
{
    return 2;
}

- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section
{
    if (section == 1)
    {
        return [self.feedbackImages count];
    }
    else if (section ==2 )
    {
        return [self.feedbackVideos count];
    }
    return 0;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    ImageCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];

    UIImage *image = [[UIImage alloc] init];

    image = [UIImage imageNamed:@"86-camera.png"];

    cell.ImageView.image = image;

    return cell;
}

我错过了什么吗?

【问题讨论】:

    标签: ios objective-c uicollectionview


    【解决方案1】:

    以索引 0 而不是 1 开始的部分,将 collectionView:numberOfItemsInSection 更改为:

    if (section == 0) //<- change to 0
    {
        return [self.feedbackImages count];
    }
    else if (section ==1 ) //<- change to 1
    {
        return [self.feedbackVideos count];
    }
    

    【讨论】:

      猜你喜欢
      • 2019-05-10
      • 1970-01-01
      • 1970-01-01
      • 2021-10-03
      • 1970-01-01
      • 2013-07-21
      • 1970-01-01
      • 1970-01-01
      • 2016-05-19
      相关资源
      最近更新 更多