我有以下 For 循环,它遍历 NSMutableArray 并调用 setImage 方法:
//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];
});
问题是图像随机出现在屏幕上,而不是按顺序加载。任何人都可以建议我如何改善这一点?
谢谢。