使用 IB 定义的设置UICollectionView(即滚动方向:水平等),并嵌入UITableViewCell使用 IB。
UICollectionViewCell显示,图像显示,但是,图像是一个一个叠放的,而不是一个图像一个图像cell的保真度。

我为每张图片制作了单独的实例变量,并且在消息中UIImageView使用 if 和switch语句也发生了同样的情况。cellForItemAtIndexPath
由于使用了 IB,因此识别错误可能会有些困难,但是,如果从代码中很明显,请您帮忙识别错误吗?谢谢。
@implementation AccountTableViewCell
- (void)setSelected:(BOOL)选定动画:(BOOL)动画
{
[超级setSelected:选定动画:动画];
// 配置选中状态的视图
imageArray = @[[UIImage imageNamed:@"image1.png"], [UIImage imageNamed:@"image2.png"], [UIImage imageNamed:@"image3.png"], [UIImage imageNamed:@"image4.png" ], [UIImage imageNamed:@"image5.png"]];
self.oCollectionView.dataSource = self;
[self.oCollectionView setFrame:self.contentView.frame];
[self.contentView addSubview:self.oCollectionView];
self.oCollectionView.backgroundColor = [UIColor clearColor];
[self.oCollectionView reloadData];
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
返回 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
返回 imageArray.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"accountCell" forIndexPath:indexPath];
UIImageView* iv = [[UIImageView alloc] init];
[cell.contentView addSubview:iv];
[iv setFrame:cell.contentView.frame];
iv.image = imageArray[indexPath.row];
返回单元格;
}
@结尾