I have images on iCloud and I subclassed UIDocument for them. Now i want to display images on the UITableView after ViewController will be loaded. So I added this code inside the viewDidLoad
method
- (void)viewDidLoad
{
...
iCloudImage *iClImage = [[iCloudImage alloc] initWithFileURL:ubiquitousPackage];
[iClImage openWithCompletionHandler:^(BOOL success) {
if (success) {
NSLog(@"iCloud document opened");
dataFromFileManager = [iClImage.imageDictionary objectForKey:img.fileName];
imageToDraw = [[[UIImage alloc] initWithData:dataFromFileManager] autorelease];
} else {
NSLog(@"failed opening document from iCloud");
imageToDraw = [UIImage imageNamed:@"defaultImage.jpg"];
}
[arrayOfImages addObject:imageToDraw];
}];
...
}
Here I'm collecting all images one-by-one into NSMutableArray *arrayOfImages
and then using that array in the - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
method.
But they are not showing in the table, because they are downloading in another thread.
How can I fix that and start showing UITableView only after images are downloaded or default images set?