【发布时间】:2015-09-25 17:49:24
【问题描述】:
我正在尝试使用以下方法加载 3 张图片。问题是这样的,我的完成块没有收到任何错误,所有 3 张图像仅在我关闭 detailViewController 并重新打开后才会显示。
我错过了什么?感谢您的帮助,非常感谢。
- (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;
}
调用 ViewDidAppear 中的所有 3 个图像
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;
});
});
}
///// 得到它的工作,但会喜欢一个解释 - 谢谢
为了让它正常工作,我直接将 sdWebImageWithURL 设置为我的原始 ImageView 并停止使用 temp UIImageView *img = [[UIimageVew alloc]init];
我来自:
[img sd_setImageWithURL:f1Url placeholderImage:[UIIm...
收件人:
[self.friendImageView1 sd_setImageWithURL:f1Url placeholderImage:[UIIm...
【问题讨论】:
标签: ios objective-c uiimageview sdwebimage