【发布时间】: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;
}
CellImageView 是 IBOutlet 的 UIImageView。
我知道我正在尝试加载相同的图像 - 这仅用于测试。图像存储在 Supporting Files 文件夹中。
问题是我得到的只是黑屏。没有显示图像。我知道我正在正确加载图像,因为我尝试对常规 ImageView 执行相同的操作并且它有效。
【问题讨论】:
-
你实现了其余的数据源方法吗?你用的是什么布局?是否调用了 cellForItem.. 方法?
标签: objective-c xcode uicollectionview collectionview uicollectionviewcell