我有一個鏈接到我的網站圖像的10個URL的數組。如何在下載完成後將通過SDWebImage下載的圖像加載到視圖控制器中?
我使用SDWebImages進行異步圖像下載,並使用for循環來運行URL數組。但是代碼會在第一個圖像下載之前通過For循環運行。因此,其餘的圖像永遠不會下載,新的視圖控制器永遠不會顯示
我該如何讓代碼運行通過for-loop,一旦圖像下載完成,它會彈出一個視圖控制器並在下載新圖像時得到更新。
這裏是我的代碼:
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]
謝謝。你對第3.1點是正確的。我認爲它會,但每次它彈出一個空的NewViewController。我的NewViewController是一個UITableView,它顯示下載的圖像的行。我會嘗試傳遞網址數組而不是圖片。謝謝! – Scott
@Scott如果你使用'UITableView',那麼這更容易。只需在'cellForRowAtIndexPath'中使用'setImageWithURL'即可。沒有'圖像'數組,沒有在'viewDidLoad'中手動創建'UIImageView'對象等等。這些'UIImageView'類別非常適合與表視圖組合。 – Rob
這些單元格中的每一個都需要顯示3個圖像。此外,我需要檢查,以確保圖像是好的,即尺寸大於100×100。我需要下載和存儲的圖像,其他地方和分析,然後將圖像加載到單元... – Scott