在我看来确实加载了:我调用了一个从 URL(异步)获取图像的函数,但有时我确实看到了图片,有时我没有
我在 viewDidLoad 中的代码
if(entry.length > 0)
{
[self getPicture];
}
else
{
ProfilePicure.image = [UIImage imageNamed:@"icon_man.png"];
}
[topView addSubview:ProfilePicure];
[self.view setBackgroundColor:UIColorFromRGB(0xffffff)];
[self.view addSubview:topView];
抓取功能:
- (void) getPicture
{
[WebImageOperations loadFromURL:entry andBlock:^(UIImage *imageData).
{
if (self.view.window)
{
UIImage *image1 = imageData;
ProfilePicure.image = image1;
}
}];
//Tried to add those to be able to see the picture, but sometimes i can't see
[self.view setNeedsDisplay];
[topView addSubview:ProfilePicure];
[topView setNeedsDisplay];
}
编辑:添加获取功能,我从这个站点复制并使用它来获取图像。
+ (void)loadFromURL:(NSString *)urlString andBlock:(void (^)(UIImage *image))processImage
{
NSMutableString *urlSTR =[[NSMutableString alloc]init];
[urlSTR appendString:@"http://www.ifat.com/files/infor/Person/"];
[urlSTR appendString:urlString];
NSURL *urlGet = [NSURL URLWithString:urlSTR];
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
NSData * imageData = [NSData dataWithContentsOfURL:urlGet];
dispatch_async(dispatch_get_main_queue(), ^{
UIImage * image = [UIImage imageWithData:imageData];
processImage(image);
});
});
}