UICollectionView选择和取消选择问题 [英] UICollectionView Select and Deselect issue
问题描述
所以我有一个主要的对象,有许多图像与它相关联。图片也是一个对象。
假设您有一个集合视图控制器,并且在该控制器中有
cellForItemAtIndexPath
很好地基于主对象,如果它有当前图像与其关联我想设置选择为true。但我希望用户能够随时取消选择当前单元格,以删除其与主对象的关联。
我发现如果设置selected to true - 如果 cellForItemAtIndexPath $ cc中主对象和图像之间存在关系$ c>,取消选择不再是一个选项。
在
didDeselectItemAtIndexPath
和
didSelectItemAtIndexPath
我用日志测试他们是否被调用。如果一个单元格被设置为selected - nether被调用,但是如果我从未在 cellForItemAtIndexPath
中设置一个单元格,我可以选择和取消选择我想要的。
这是集合视图应该工作的预期方式吗?我读的文档,它似乎没有谈论这是这样的。我解释文档意味着它的工作方式一个表视图单元格。有一些明显的变化
这也显示控制器设置正确,并使用适当的委托方法... hmmmm
我有同样的问题,ie。在中设置
然后无法通过点击取消选择单元格 cell.selected = YES
[UICollectionView collectionView:cellForItemAtIndexPath:]
现在的解决方案:我调用两者 [UICollectionViewCell setSelected:]
和 [UICollectionView collectionview:cellForItemAtIndexPath:]
中的 [UICollectionView selectItemAtIndexPath:animated:scrollPosition:]
b $ b
So I have a main object that has many images associated with it. An Image is also an object.
Say you have a collection view controller, and in that controller you have
cellForItemAtIndexPath
well based on the main object, if it has the current image associated with it I want to set selected to true. But I want the user to be able to "un-select" that current cell at any time to remove its association with the main object.
I find that if you set "selected to true" - if there is an relation between the main object and image in cellForItemAtIndexPath
, de-selection is no longer an option.
in
didDeselectItemAtIndexPath
and
didSelectItemAtIndexPath
I test with a log to see if they are called. If a cell is set to selected - nether gets called, but If I never set a cell to selected in cellForItemAtIndexPath
I can select and deselect all I want.
Is this the intended way a collection view is supposed to work? I read the docs and it does not seem to talk about this being so. I interpret the docs to mean it works the way a table view cell would. with a few obvious changes
This also shows the controller is set up correct and is using the appropriate delegate methods.... hmmmm
I had the same issue, ie. setting cell.selected = YES
in [UICollectionView collectionView:cellForItemAtIndexPath:]
then not being able to deselect the cell by tapping on it.
Solution for now: I call both [UICollectionViewCell setSelected:]
and [UICollectionView selectItemAtIndexPath:animated:scrollPosition:]
in [UICollectionView collectionView:cellForItemAtIndexPath:]
.
这篇关于UICollectionView选择和取消选择问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!