[英]UICollectionView reloadData ghost cells
I came here because I have a pretty weird problem with my UICollectionView. 我来这里是因为我的UICollectionView有一个很奇怪的问题。
Imgur album with all the screens I would like to share : http://imgur.com/a/v3sox 我想与所有屏幕共享的Imgur专辑 : http : //imgur.com/a/v3sox
First of all, here's what my app looks like with no problem: Image 2 of the album. 首先,这是我的应用没问题的样子:专辑的图片2。
Notice the refresh button in the top-right corner, this is the one which is giving me problems. 请注意右上角的刷新按钮,这是给我带来麻烦的按钮。
When I scroll down the UICollectionView very fast, and press "refresh" while the Collection View is still scrolling, I've got "cell leftovers" which do not belong to anybody and just stay on the screen. 当我快速向下滚动UICollectionView并在Collection View仍在滚动时按“刷新”时,我发现“单元格剩余”不属于任何人,而是停留在屏幕上。 (ex: Image 1 of the album)
(例如:相册的图片1)
I don't understand what's happening because in my refresh method I have: 我不知道发生了什么,因为在我的刷新方法中,我有:
- (void)refreshData
{
//A bunch of code before I reset the data
dispatch_async(dispatch_get_main_queue(), ^{
//Reset data
currentProjects = nil;
[self.projectsCollectionView reloadData];
//Some other stuff concerning the little "Chargement..." view
};
}
The cells then proceed to stay on my screen on every folder, so if I choose another folder, I'll get Image 3 of the album (notice the labels for the last 4 cells, they are mixed up, because the previous cells are still on the screen when they shouldn't be.) 然后,这些单元格继续停留在屏幕上每个文件夹的屏幕上,因此,如果我选择另一个文件夹,我将获得相册的图片3(请注意最后4个单元格的标签,它们混合在一起了,因为以前的单元格仍然在屏幕上不应该出现的时候显示。)
Has anybody got an idea on what could possibly cause this? 有谁知道可能导致这种情况的原因吗? Thanks a lot for your time
非常感谢您的时间
PS: sorry i put all the screens in an album, couldn't post more than 2 links so I had to improvise PS:对不起,我把所有屏幕都放在了一个相册中,不能发布两个以上的链接,所以我不得不即兴创作
Just had the same problem too. 也有同样的问题。 I solved it by modifying the
UICollectionViewCell
. 我通过修改
UICollectionViewCell
解决了它。
(note: my code is c# using MonoTouch). (注意:我的代码是使用MonoTouch的c#)。
before the cell was creating the objects each time. 在单元每次创建对象之前。 ie.
即。
textView = new UITextField()
{
BackgroundColor = UIColor.Clear,
TextColor = UIColor.LightGray,
Text = Title
};
to fix it, check for the object, and update it accordingly. 要修复它,请检查对象,然后进行相应更新。
if (textView == null)
{
textView = new UITextField()
{
BackgroundColor = UIColor.Clear,
TextColor = UIColor.LightGray,
Text = Title
};
}
else
textView.Text = Title;
now when reload data is called on the CollectionView, it reloads correctly. 现在,当在CollectionView上调用重新加载数据时,它将正确地重新加载。
I have had this similar issue once. 我曾经有过类似的问题。 The problem is my custom cell creates subview again and again.
问题是我的自定义单元一次又一次创建子视图。
From my guess, you should change the value of the label instead re-create it after dequeue. 根据我的猜测,您应该更改标签的值,而不是在出队后重新创建它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.