ios - Cache Images and load on scroll in UICollectionView with SDWebImageDownloader Xamarin -
i have uicollectionview cells images downloaded url along headers. below :-
internal void updatecell(profilevalues mdata) { var murl = "someurl"; var manager = sdwebimagemanager.sharedmanager; manager.imagecache.maxcacheage = 86400; sdwebimagedownloader mdownloader = manager.imagedownloader; var authtoken = "sometoken""; mdownloader.sethttpheadervalue(authtoken, "authorization"); mdownloader.sethttpheadervalue("application/json; odata=verbose", "accept"); mdownloader.sethttpheadervalue("f", "x-forms_based_auth_accepted"); try { mdownloader.downloadimage( url: new nsurl(murl), options: sdwebimagedownloaderoptions.progressivedownload, progressblock: (receivedsize, expectedsize) => { // track progress... }, completedblock: (image, data, error, finished) => { if (image != null && finished) { invokeonmainthread(() => { this.imgprofilepic.image = image; }); } if (error != null) { invokeonmainthread(() => { this.imgprofilepic.image = errorimage; this.imgprofilepic.backgroundcolor = uicolor.fromrgb(52, 31, 71); //this.imgprofilepic.layer.cornerradius = this.imgprofilepic.frame.size.width / 2; this.imgprofilepic.clipstobounds = true; this.imgprofilepic.layer.borderwidth = 3.0f; this.imgprofilepic.layer.bordercolor = uicolor.white.cgcolor; }); } } ); } catch (exception ex) { } }
but on every scroll cells reloaded , images downloaded everytime. how can cache images , load images cache on scroll? appreciated.
use ffimageloading package & use class cachedimage place of image
var cachedimage = new cachedimage() { horizontaloptions = layoutoptions.center, verticaloptions = layoutoptions.center, widthrequest = 300, heightrequest = 300, cacheduration = timespan.fromdays(30), downsampletoviewsize = true, retrycount = 0, retrydelay = 250, transparencyenabled = false, source = "http://loremflickr.com/600/600/nature?filename=simple.jpg", cachekeyfactory = new customcachekeyfactory(), };
Comments
Post a Comment