【问题标题】:unable to load collection view cell无法加载集合视图单元格
【发布时间】:2015-04-21 10:27:37
【问题描述】:

我能够加载集合视图但无法加载单元格。下面是我正在使用的代码。

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

   static NSString *identifier = @"reuseCell";
    [self.view_dashboard registerClass:[UICollectionViewCell class]
            forCellWithReuseIdentifier:@"reuseCell"];

    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];

   recipeImageView = (UIImageView *)[cell viewWithTag:100];

    recipeImageView.image= [UIImage imageNamed:[dashBoard_img objectAtIndex:indexPath.row]];

    return cell;
}

【问题讨论】:

  • [self.view_dashboard registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"reuseCell"];这一行放在cellForItemAtIndexPath之外,你可以在viewDidAppear里面加进去
  • 有注册笔尖文件吗?
  • 你设置断点了吗? cellForItemAtIndexPath: 是否被调用?您不需要每次都为每个单元格注册课程。你只需要在你的 UIViewController 的其他地方调用一次。
  • 是的,我在上面添加了行但是,我们无法加载单元格。@病毒
  • 您是否实现了数据源协议?...还有...您是否将您的 collectionview 数据源委托设置为视图控制器?...还检查返回值:numberOfSectionsInCollectionView 和 numberOfItemsInSection

标签: ios objective-c iphone uicollectionview


【解决方案1】:

您的代码似乎没有什么特别的问题。

在集合视图中加载单元格需要的工作不仅仅是这种单一方法。

我将开始进一步解释,但我只是向您阅读文档。相反,请自己阅读 Apple 文档。

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UICollectionView_class/index.html#//apple_ref/doc/uid/TP40012177-CH1-SW4

【讨论】:

    猜你喜欢
    • 2021-01-31
    • 2016-12-06
    • 1970-01-01
    • 2018-03-25
    • 2020-07-30
    • 2018-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多