我在我的应用程序中使用了collectionView。我在didSelect委托中设置单元格backgroundView的图像。但是,当我选择一个单元格索引路径图像正在设置为3单元格索引路径。当我滚动collectionView图像随机变化?请帮帮我。提前致谢。UICollectionView - 图像随机设置
- (void)viewDidLoad
{
[super viewDidLoad];
[collection registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:uio];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection: (NSInteger)section
{
return 50;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [collection dequeueReusableCellWithReuseIdentifier:uio
forIndexPath:indexPath];
cell.backgroundColor = [UIColor whiteColor];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"index %@",indexPath);
UICollectionViewCell *cell = [collection cellForItemAtIndexPath:indexPath];
cell.backgroundView =[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"download.jpg"]];
}
请附上您的代码 – dKrawczyk
请出示您的cellForItemAtIndexPath()方法 –
没有看到你的代码很难告诉,但我的猜测是,单元格正在重新使用,当你滚动。 – jervine10