4

I came here because I have a pretty weird problem with my UICollectionView.

Imgur album with all the screens I would like to share: https://i.stack.imgur.com/CKy9x.jpg

First of all, here's what my app looks like with no problem: Image 2 of the album.

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. (ex: Image 1 of the album)

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.)

Has anybody got an idea on what could possibly cause this? Thanks a lot for your time

P.S: sorry i put all the screens in an album, couldn't post more than 2 links so I had to improvise

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Drayae
  • 241
  • 2
  • 10

2 Answers2

2

Just had the same problem too. I solved it by modifying the UICollectionViewCell.

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

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.

Sudmanche
  • 81
  • 1
  • 9
0

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.

Roger
  • 389
  • 2
  • 6