- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
UIImageView *img;
UICollectionViewCell *myCell=[collectionView cellForItemAtIndexPath:indexPath];
img=(UIImageView*)[myCell viewWithTag:101];
if (myCell.selected) {
[myCell.img setImage:[UIImage imageNamed:@"images-2.png"]];
}
[collectionView reloadData];
}
- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath{
UIImageView *img;
UICollectionViewCell *myCell=[collectionView cellForItemAtIndexPath:indexPath];
img=(UIImageView*)[myCell viewWithTag:101];
[img setImage:[UIImage imageNamed:@"images.png"]];
[collectionView reloadData];
}
-1
A
回答
0
问题与重载数据后[collectionView reloadData];
你会改变图像中cellForItemAtIndexPath
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = (UICollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
if(indexPath.row == selectedIndexPath)
{
[img setImage:[UIImage imageNamed:@"selected image"]];
}
else
{
[img setImage:[UIImage imageNamed:@"images.png"]];
}
}
- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath
{
selectedIndexPath=indexPath.row;
[collectionView reloadData];
}
注:最初设置selectedIndexPath = -1,则表明在集合视图中的答复
0
请勿在委托回调中调用reloadData
。这很容易导致未定义的行为,并导致您提到的有关集合视图的问题无法正确处理选择状态。
通常调用reloadData
删除所有选择。
+0
由于没有选择我不是!重新加载单元格,但我想改变单元格的图像..你可以建议如何做到这一点? – 2014-10-08 06:26:06
相关问题
- 1. 当选择单元格时,UITableViewCell子视图消失
- 2. 如何选择何时返回集合视图单元格
- 3. 选择单元格集合
- 4. UITableViewCell didSelectRowAtIndexPath。当我选择一个新单元格时,取消选择“未选定”单元格
- 5. 当网格失焦时,取消选择slickgrid中的单元
- 6. 无法在集合视图中选择几个单元格
- 7. 如何在集合视图中选择单元格?
- 8. 集合视图单元格按钮不触发动作
- 9. 集合视图单元格不显示在集合视图中?
- 10. 从集合视图中删除集合视图单元格Xcode
- 11. 集合视图单元格不允许我选择
- 12. 在选择/取消选择时调整表格单元格
- 13. 当呈现弹出窗口视图时,如何让用户在父集合视图中选择单元格?
- 14. 当点击另一个表格时取消选择表格视图单元格中的按钮
- 15. 要取消选择表格单元格
- 16. 当您选择单元格时,UITableViewCell更改单元格的大小
- 17. PagingScrollTable - 当选择单元格时消失backround图像
- 18. navigationController弹出视图时取消选定单元格的内容?
- 19. 手动触发单元格选择TableView
- 20. 集合视图中的默认选定单元格swift
- 21. 从UITest的收集视图中选择第一个单元格
- 22. Swift - 在表视图单元格中未触发按钮操作
- 23. Vaadin 8:绑定的CheckBoxGroup SelectionListener在取消选择时未触发
- 24. 在tableview中取消选择先前选择的单元格
- 25. Excel VBA:取消选择单元格
- 26. 如何在用户返回表视图时执行单元格取消选择?
- 27. 表格视图单元格内的集合视图
- 28. UICollectionViewCell中的单元格自动取消选择或取消选择手指
- 29. 当包含公式的单元格更新时,onEdit未触发?
- 30. 当选择单元格时,Swift tableView单元格子视图闪烁(消失然后重新出现)
非常感谢回复!如何获得selectcell? – 2014-10-08 06:12:42
由于NANNAV是一个很好的帮助!我想你的ID联系..请 – 2014-10-09 08:20:55
@ mubibegum有没有在这个网站上的个人聊天,在这个网站添加您的问题,任何一个帮助给你。 – NANNAV 2014-10-09 08:40:49