ios - Best way to reload UICollectionView -


i have uicollectionview load collection of photos photo library.

for asset: phasset in self.photoassets! {                             sfsimagemanger.imagefromasset(asset, isoriginal: false, tosize: cgsize(width: 150, height: 150), resulthandler: { (image: uiimage?) in                                 guard image != nil else { return }                                 dispatch_async(dispatch_get_main_queue(), {                                     self.photos.append(image!)                                     self.albumcollection.reloaddata()                                 })                             })                         } 

this how load photos. problem when have many photos, more 500, collectionview flickers when scroll , collectionview selection doesn't work until loop completes.

i not want app show loading progress , freeze ui also. so, how increase performance in case?

what create didset in photos array this:

var photos = [uiimages]() {     didset {         albumcollection.reloaddata()     { } 

and suppose loop in function, in case create temporary array , initialise photos array, append images temporary array , after loop assign temporary array original photos array. idea:

var tempphotos = photos    asset: phasset in self.photoassets! {                             sfsimagemanger.imagefromasset(asset, isoriginal: false, tosize: cgsize(width: 150, height: 150), resulthandler: { (image: uiimage?) in                                 guard image != nil else { return }                                 dispatch_async(dispatch_get_main_queue(), {                                     self.tempphotos.append(image!)                                 })                             })                         }     photos = tempphotos 

this way collectionview update once. greetings jorge paravicini.


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -