0
我有以下For循環通過一個NSMutableArray該迭代並調用setImage方法:更新圖像載入在For循環與GCD螺紋 - 的iOS
//Code to iterate through pictures and create ImageView class for each one.
for (int i =0; i<=[pictureThumbnailArray count]-1; i++) {
NSLog(@"Thumbnail count is %d", [pictureThumbnailArray count]);
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^(void) {
[self setImage:[pictureThumbnailArray objectAtIndex:i]:i];
});
}
的setImage方法設置在圖片上的各種參數,然後最終將其添加到主線程的子視圖上:
dispatch_sync(dispatch_get_main_queue(), ^(void) {
[self.view addSubview:onePicture];
});
問題是圖像隨機出現在屏幕上,而不是逐個加載。任何建議可以提高我的能力嗎?
謝謝。