[英]UICollectionView.reloadData or UICollectionView.deleteItemsAtIndexPaths makes cell hidden but still clickable
I got a UICollectionView with several cells in it. 我有一个包含几个单元格的UICollectionView。
I deleted the first cell by clicking a button on it, it works good no matter I choose [UICollectionView reloadData] or [UICollectionView deleteItemsAtIndexPaths:]
. 我通过单击第一个单元格上的按钮删除了该单元格,无论选择[UICollectionView reloadData] or [UICollectionView deleteItemsAtIndexPaths:]
,它都可以正常工作。
Now the following cells will move forward, so the first cell now would be the second one before the deletion, easy to understand, right? 现在,以下单元格将向前移动,因此第一个单元格将是删除之前的第二个单元格,易于理解,对吗?
Now comes the weird part: 现在出现了奇怪的部分:
I click on the first cell's delete button, it shows: 我单击第一个单元格的删除按钮,它显示:
<MyCell: 0x7fc5de566590; baseClass = UICollectionViewCell; frame = (220 20; 80 104); alpha = 0; hidden = YES; layer = <CALayer: 0x7fc5de566740>>
I print the visible cells: 我打印可见的单元格:
< __NSArrayM 0x7fc5de655830>( < MyCell: 0x7fc5de55c060; baseClass = UICollectionViewCell; frame = (20 134; 80 104); layer = < CALayer: 0x7fc5de55c210>>, < MyCell: 0x7fc5de635290; baseClass = UICollectionViewCell; frame = (120 134; 80 104); layer = < CALayer: 0x7fc5de635440>> )
see? 看到? the cell I clicked on is actually that one been deleted, unless it's NOT! 我单击的单元格实际上是一个被删除的单元格,除非不是! it has a flag hidden = YES
, and it has a frame and superview also(yes the superview is the collection view). 它有一个flag hidden = YES
的flag hidden = YES
,也有一个框架和一个超级视图(是的超级视图是集合视图)。
Now that brings me problem because I meant to delete this guy MyCell: 0x7fc5de55c060. 现在这给我带来了问题,因为我打算删除此人MyCell:0x7fc5de55c060。
So any clue on this? 那么有什么线索吗? Thank you! 谢谢!
Problem solved. 问题解决了。 It's because I override hittest in MyCell. 这是因为我在MyCell中覆盖了hittest。 I didn't expect that deleted cells would still be subview of the collection view. 我没想到被删除的单元格仍然是集合视图的子视图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.