【问题标题】:Using UICollectionView inside regular UIView在常规 UIView 中使用 UICollectionView
【发布时间】:2012-11-12 06:48:05
【问题描述】:

我创建了一个常规视图,我想将其中一半与UICollectionView 一起使用。 我将UICollectionView 拖放到视图上并调整其大小。我拖了一个 UICollectionViewCell 新的视图并设计了它(全部在 XCode 的布局构建器中)。

UICollectionViewCell 类被称为ImageCell,所以我在viewDidLoad 事件中将单元类注册到UICollectionView

[self.imagesCollectionView registerClass:[ImageCell class] forCellWithReuseIdentifier:@"ImagePhotoCell"];

这是我尝试将图像加载到集合视图单元格的方式:

- (UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
ImageCell *imageCell = [imagesCollectionView dequeueReusableCellWithReuseIdentifier:@"ImagePhotoCell" forIndexPath:indexPath];
imageCell.CellImageView.image = [UIImage imageNamed:@"IMG_2284.JPG"];
return imageCell;

}

CellImageViewIBOutletUIImageView。 我知道我正在尝试加载相同的图像 - 这仅用于测试。图像存储在 Supporting Files 文件夹中。

问题是我得到的只是黑屏。没有显示图像。我知道我正在正确加载图像,因为我尝试对常规 ImageView 执行相同的操作并且它有效。

【问题讨论】:

  • 你实现了其余的数据源方法吗?你用的是什么布局?是否调用了 cellForItem.. 方法?

标签: objective-c xcode uicollectionview collectionview uicollectionviewcell


【解决方案1】:

我遇到了类似的问题,这似乎是由于未加载 NIB 造成的。 尝试将 viewDidLoad 注册调用替换为以下内容:

UINib *cellNib = [UINib nibWithNibName:@"nibFileName" bundle:nil];
[self.imagesCollectionView registerNib:cellNib forCellWithReuseIdentifier:@"ImagePhotoCell"];

【讨论】:

    猜你喜欢
    • 2018-01-31
    • 2013-08-10
    • 1970-01-01
    • 2013-01-30
    • 1970-01-01
    • 1970-01-01
    • 2015-03-12
    • 2018-07-19
    • 1970-01-01
    相关资源
    最近更新 更多