UICollectionView reloads wrong images on scroll

后端 未结 3 2147
天命终不由人
天命终不由人 2021-02-14 11:46

In the code below, I download image URLs from a text file, store it in a NSMutableArray, then download the images from from those URLS in CellforItemAtIndexPath. However, when I

3条回答
  •  半阙折子戏
    2021-02-14 12:33

    I see that you have already answered this question, but still want to share my experience.

    I had the same problem.

    In my case, the reason of this problem was the following function: collectionView.dequeueReusableCell(...).

    The type of cells was the same in every case, but data was different:

    • In some cases data for a specific cell contained an image.
    • In some cases data for a specific cell did not contain an image, it was nil.

    When image was nil I was not setting an image to the imageView. In such case collection view reuses an image of of other cell (Wrong image for a current cell).

    Solution is very simple: Just set nil, if imageView does not contain an image.

    Hope this will help you.

提交回复
热议问题