In my app, I load image from the URL:
-(void)loadImages
{
...
image1 = [UIImage imageWithData:[NSData dataWithContentsOfURL:imgUrl1]];
}
In order to avoid blocking the main thread until the download has completed I call this method in
-viewDidAppear using GCD
:
dispatch_async( dispatch_get_global_queue(0,0), ^{
[self loadImages];
});
However, when I open my view controller
with the imageView
at the first time, the imageView
is empty (even if I wait for a long time) but after I open this view controller
again and image appears and everything is good to go.
Where is my mistake ? Sorry, new to multithreading :)
EDIT:
I also forgot to mention, that I use the image in the tableView
when I get it:
cell.imageView.image = image1;