滚动时选择多个值随机播放:UICollectionView [英] Selecting multiple values shuffle when scrolled: UICollectionView

查看:26
本文介绍了滚动时选择多个值随机播放:UICollectionView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在 UICollectionView 中选择多个单元格,滚动时选择更改.为什么会这样,请指导.下面是代码.我试过了.

Trying to select the multiple cells in UICollectionView and when scrolled the selection c hanges. Why it is happening, please guide. Below is code. i tried.

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
printf("Selected View index=%d",indexPath.row);

itemPaths  = [self.collectionView indexPathsForSelectedItems];

UICollectionViewCell* cell=[self.collectionView cellForItemAtIndexPath:indexPath];
cell.contentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"blue_s.png"]];
}

- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell* cell=[self.collectionView cellForItemAtIndexPath:indexPath];
cell.contentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"yellow_seat.png"]];

}

我还应该尝试什么.

推荐答案

因为您可能会重复使用您的单元格,所以当您将单元格放回 (cellForItemAtIndexPath) 时,您需要检查是否选择了 indexPath 并为您的单元格着色.您可能还想对单元格进行脱色,因为在某些情况下,重用功能可能会发回一个不应该着色的单元格.

Since you are likely reusing your cells, when you hand the cells back out (cellForItemAtIndexPath) you need to check if the indexPath is selected and color up your cell. You will likely want to decolor your cells too since the reuse function may send back a colored up cell in some cases when it should not.

这篇关于滚动时选择多个值随机播放:UICollectionView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆