【发布时间】:2015-02-25 03:43:22
【问题描述】:
我使用以下代码将图像从数组添加到 uicollectionview 单元格。
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
UICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];
UIImageView *emoji = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
emoji.image = [UIImage imageNamed:[imagePack objectAtIndex:indexPath.row]];
emoji.contentMode = UIViewContentModeScaleAspectFit;
[cell.contentView addSubview:emoji];
return cell;
}
当我向下滚动 UICollectionView 然后向上滚动时,图像会重新出现在每个单元格的顶部。假设我有单元格 1 的图像 1,单元格 2 的图像 2,依此类推。如果我向下滚动然后向上滚动,在单元格 1 中我有图像 1,图像 1 的顶部是图像 2。
在我滚动之后,它会弄乱图像,在滚动看起来正常之前。
请知道我做错了什么?
【问题讨论】:
标签: objective-c uicollectionview