UICollectionView reloadData ghost cells

I came here because I have a rather strange problem with my UICollectionView.

Imgur album with all screens I would like to share: http://imgur.com/a/v3sox

Firstly, here is what my application looks like without any problems: Image 2 albums.

Pay attention to the update button in the upper right corner, this is a problem that gives me problems.

When I quickly scroll through the UICollectionView and click Refresh while browsing the collection is still scrolling, I have โ€œcell residuesโ€ that do not belong to anyone and just remain on the screen. (example: image of 1 album)

I do not understand what is happening because in my update method I:

- (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 }; } 

Then the cells continue to remain on my screen in each folder, so if I select a different folder, I will get an image of 3 albums (pay attention to the labels for the last 4 cells, they are mixed, because the previous cells remain on the screen when they should not be .)

Has anyone figured out what can do this? Thanks so much for your time.

PS: sorry, I put all the screens in the album, could not post more than two links, so I had to improvise

+4
source share
2 answers

I had the same problem too. I solved this by changing the UICollectionViewCell .

(note: my code is C # using MonoTouch).

before the cell created objects every time. i.e.

 textView = new UITextField() { BackgroundColor = UIColor.Clear, TextColor = UIColor.LightGray, Text = Title }; 

to fix it, check on the item and update it accordingly.

 if (textView == null) { textView = new UITextField() { BackgroundColor = UIColor.Clear, TextColor = UIColor.LightGray, Text = Title }; } else textView.Text = Title; 

now that reload information is called in CollectionView, it reloads correctly.

+2
source

I had the same problem once. The problem is that my custom cell creates subview over and over again.

From my guess, you should change the label value instead of re-creating after dequeue.

0
source

Source: https://habr.com/ru/post/1489442/


All Articles