【发布时间】:2013-09-28 19:38:33
【问题描述】:
UICollectionView 的设置是使用 IB 定义的(即滚动方向:水平等),并使用 IB 嵌入到UITableViewCell。
UICollectionViewCell 显示,图像显示,但是,图像堆叠在另一个之上,而不是保真cell 一个图像。
我为每张图片创建了单独的 UIImageView 作为实例变量,并且在 cellForItemAtIndexPath 消息中使用 if 和 switch 语句也发生了同样的情况。
由于使用了 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];
返回单元格;
}
@end
【问题讨论】:
标签: objective-c uitableview uiimageview uicollectionviewcell