I am attempting to load 3 images using the method below. The problem is this, I recieve no errors from my completion block and all 3 images only show after I close my detailedViewController and reopen it.
What am I missing ? Thanks for any help, greatly 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 to say that the image was 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 all 3 images in ViewDidAppear
if ([self loadImageFav1:self.emailID] != nil) {
// call the same method on a 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 the main thread
dispatch_async(dispatch_get_main_queue(), ^{
self.friendImageView1.image = tmpF1;
self.friendImageView2.image = tmpF2;
self.friendImageView3.image = tmpF3;
});
});
}
///// GOT IT WORKING BUT WOULD LOVE AN EXPLICATION - THANKS
So to get it working I set the sdWebImageWithURL to my original ImageView directly and stopped using the temp UIImageView *img = [[UIimageVew alloc]init];
I went from:
[img sd_setImageWithURL:f1Url placeholderImage:[UIIm...
To:
[self.friendImageView1 sd_setImageWithURL:f1Url placeholderImage:[UIIm...