I have an array of 10 URLs that are linked to images of my website.
I'm using SDWebImages for async image downloading and a for loop to run thru the array of URLs. But the code would just run thru the For-loop before the first image can be downloaded. Therefore, the rest of the images never gets downloaded and the new view controller is never displayed
How can I allow the code to run thru the for-loop, and once an image has been downloaded, it pops up a view controller and gets updated whenever a new image is downloaded.
Here's my code:
NewViewController *vc = [[NewViewController alloc] initWithNibName:nil bundle:nil];
NavigationController *navigationController = [[NavigationController alloc] initWithRootViewController:vc];
for (NSString *url in urls) {
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectZero];
[imageView setImageWithURL:[NSURL URLWithString:url]
placeholderImage:[UIImage imageNamed:@"post-imagePlaceholder"]
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
item.image = image;
[self.images addObject:item];
vc.results = self.images;
;
}
}];
}
[self presentViewController:navigationController animated:YES completion:nil]