私のビューではロードされました: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);
});
});
}