简体   繁体   English

UICollectionView.reloadData或UICollectionView.deleteItemsAtIndexPaths使单元格隐藏但仍可单击

[英]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: 现在出现了奇怪的部分:

  1. 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>> 
  2. 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 = YESflag 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.

相关问题 UICollectionView.reloadData()更改单元格顺序| iOS Swift - UICollectionView.reloadData() changes cell order | iOS Swift 如何在Swift中正确地执行此UICollectionView.deleteItemsAtIndexPaths? - How do I do do this UICollectionView.deleteItemsAtIndexPaths Correctly in Swift? UICollectionView.reloadData()不会触发UICollectionDataSource方法 - UICollectionView.reloadData() do NOT trigger UICollectionDataSource methods 调用UICollectionView.reloadData()是不是很糟糕? 如果是这样,为什么? - Is calling UICollectionView.reloadData() bad practice? If so, why? UICollectionView内容在reloadData之后被隐藏 - UICollectionView content is hidden after reloadData deleteItemsAtIndexPaths中的UICollectionView断言失败 - UICollectionView Assertion failure in deleteItemsAtIndexPaths UICollectionView deleteItemsAtIndexPaths失败 - UICollectionView deleteItemsAtIndexPaths failure 如何从动画中删除UICollectionView中唯一的单元格(deleteItemsAtIndexPaths)? - How to delete the only cell from UICollectionView with animation (deleteItemsAtIndexPaths)? 动画中的contentOffset在deleteItemsAtIndexPaths上的UICollectionView中发生更改 - Animating contentOffset changes in a UICollectionView on deleteItemsAtIndexPaths UICollectionView.reloadData()在添加第一个项目后起作用,然后似乎在后面运行了一个 - UICollectionView.reloadData() works after adding first item, then seems to run one behind
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM