ios - SDWebImage Not showing after download (only after reopening VController) -


i attempting load 3 images using method below. problem this, recieve no errors completion block , 3 images show after close detailedviewcontroller , reopen it.

what missing ? help, appreciated.

- (uiimage*)loadimagefav1:(nsstring *)nameemail {         uiimageview *img =[[uiimageview alloc]init];     //    nsstring *strback = [nsstring stringwithformat:@"%@%@%@", self.urlprefix,[self.selectedprofile objectforkey:nameemailpro],@"_b.png"];     nsstring *strprofi = [nsstring stringwithformat:@"%@%@%@", self.urlprefix,nameemail,@"_fav1.png"];     //     //    nsurl *bkgurl = [nsurl urlwithstring:[strback stringbyaddingpercentescapesusingencoding:nsutf8stringencoding]];     nsurl *f1url = [nsurl urlwithstring:[strprofi stringbyaddingpercentescapesusingencoding:nsutf8stringencoding]];     //    // set imges below       nslog(@"selected fprofile ......str data...%@",strprofi);     ////////strt      weakimageviewf1= self.friendimageview1;     [img sd_setimagewithurl:f1url            placeholderimage:[uiimage imagenamed:@"profile-1.jpg"]                     options:sdwebimageretryfailed                   completed:^(uiimage *image, nserror *error, sdimagecachetype cachetype, nsurl *imageurl) {                        nslog(@"error...back..log %@", error);                        if (image) {                           // update model image downloaded                            nslog(@"complete...background...ssssss");                            weakimageviewf1.image = image;                           [weakimageviewf1 setneedslayout];                       }                   }];     //////     // test simple call //    [img sd_setimagewithurl:f1url placeholderimage:[uiimage imagenamed:@"profile-1.jpg"] completed:^(uiimage *image, nserror *error, sdimagecachetype cachetype, nsurl *imageurl) { //        if(error){ //            nslog(@"callback error:%@",error); //        } //        if(image){ //            nslog(@"callback image:%@",image); //        } //    }];       return img.image;   } 

call 3 images in viewdidappear

if ([self loadimagefav1:self.emailid] != nil) {  // call same method on background thread dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_default, 0), ^{      uiimage *tmpf1 = [self loadimagefav1:self.emailid];     uiimage *tmpf2 = [self loadimagefav2:self.emailid];     uiimage *tmpf3 = [self loadimagefav3:self.emailid];                 // update ui on main thread     dispatch_async(dispatch_get_main_queue(), ^{          self.friendimageview1.image = tmpf1;         self.friendimageview2.image = tmpf2;         self.friendimageview3.image = tmpf3;       });  }); 

}

///// got working love explication - thanks

so working set sdwebimagewithurl original imageview directly , stopped using temp uiimageview *img = [[uiimagevew alloc]init];

i went from:

[img sd_setimagewithurl:f1url placeholderimage:[uiim... 

to:

[self.friendimageview1 sd_setimagewithurl:f1url  placeholderimage:[uiim... 

it concurrency problem. sdwebimage asynchronous you're screwing doing own manual asynchronous thread.

here you're saying:

  1. in new background thread (thread a), start downloading images.
  2. this new background thread (thread a) starting it's own background thread (thread b, sdwebimage doing you).
  3. your background thread ends.
  4. the code in dispatch_get_main_queue section runs, thread b still in process of downloading images aren't available yet.

the reason show next time because sdwebimage has cached them first attempt.

to fix problem should move code runs in dispatch_get_main_queue section completed block sdwebimage call.

edit:

the reason change fixed because sdwebimage takes care of loading uiimage uiimageview gave in first place. saying "load image uiimageview named img , assign image other uiimageview named self.friendimageview1", @ point in time current image assigned img placeholder image, since 1 internet had not yet downloaded. said, sdwebimage doing download automatically in background thread, , when download done assigning downloaded image uiimageview calling on. original code added middleman.


Comments