How to get a snappy UICollectionView with lots of images (50-200)?

前端 未结 2 825
无人及你
无人及你 2021-02-01 08:44

I\'m using UICollectionView in an app that is displaying quite a lot of photos (50-200) and I\'m having issues getting it to be snappy (as snappy as Photos app for

2条回答
  •  野性不改
    2021-02-01 09:03

    I think that approach #3 is the best way to go, and I think I may have spotted the bug.

    You're assigning to @image, a private variable for the whole collection view class, in your operation block. You should probably change:

    @image = UIImage.imageWithContentsOfFile(image_path)
    

    to

    image = UIImage.imageWithContentsOfFile(image_path)
    

    And change all the references for @image to use the local variable. I'm willing to bet that the problem is that every time you create an operation block and assign to the instance variable, you are replacing what is already there. Due to some of the randomness of how the operation blocks are dequeued, the main queue async callback is getting the same image back because it is accessing the last time that @image was assigned.

    In essence, @image acts like a global variable for the operation and async callback blocks.

提交回复
热议问题