ios - SDWebImage Complete closure is called 4 times per image -


i use sdwebimage progress.

i use following code in `init()`` constructor:

if let url: nsurl = nsurl(string: previewcard.getimageurls().getwithint(0) as! string) {   self.imageview?.setimagewithurl(url, placeholderimage: mgimage.imagewithcolor(uicolor.clearcolor()), options: sdwebimageoptions.refreshcached, completed: { (image:uiimage!, error:nserror!, type:sdimagecachetype, loadurl:nsurl!) -> void in      println("-------------- done")     }, usingactivityindicatorstyle: uiactivityindicatorviewstyle.gray)  } 

the console output is:

 println("-------------- done")  println("-------------- done")  println("-------------- done")  println("-------------- done") 

why complete closure called 4 times? how can prevent called 4 times?

edit: verified init() method called once. wherever call setimagewithurl method complete closure called @ least twice.

it's because you're specifying "refreshcached". check out documentation here. line under sdwebimagerefreshcached:

the completion block called once cached image , again final image

so should @ least 2 callbacks. since you're getting 4 callbacks rather two, guess you're either getting errors (so check if "error" param tells useful), or you're refreshing large images , getting progress updates along way. regardless, last callback 1 contains refreshed image want.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -