所以这段代码基本上是从服务器获取数据,创建图像,然后将其添加到视图中。
但是,我希望它一次更新一个视图。
现在,视图在所有图像都加载后立即更新。
我想在每次上传新图像时更新视图 - 这应该发生在 addImage 方法中,但它只是在等待所有图像加载。
我尝试使用 dispatch_async 来解决这个问题,但它不起作用。
那么如何一次加载一张图片呢?
AFJSONRequestOperation *operation =
[AFJSONRequestOperation JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
//some code not displayed here that parses the JSON
for (NSDictionary *image in images){
if ([[image objectForKey:@"ContentType"] isEqualToString:@"image/png"]){
NSString *imgLink = [[image objectForKey:@"MediaUrl"] JSONStringWithOptions:JKSerializeOptionPretty includeQuotes:NO error:nil];
NSURL *url = [NSURL URLWithString:path];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:data cache:NO]
dispatch_async(dispatch_get_main_queue(), ^{
[self addImage:img];
//This method adds the image to the view
});
}
}
}
更新:这不是表格视图,图像作为子视图添加到 UIView