이 코드는 기본적으로 서버에서 데이터를 가져 와서 이미지를 만든 다음보기에 추가합니다.이미지를 한 번에 불러 오기
그러나 한 번에 하나씩보기를 업데이트하고 싶습니다.
지금은 모든 이미지가로드 된 후 즉시 모든 이미지로보기가 업데이트됩니다.
새 이미지를 업로드 할 때마다보기를 업데이트하고 싶습니다.이 작업은 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의
시도 [자기 setNeedsDisplay]; – Shmidt
아니, 그 효과, 같은 결과가 없었다. 나는 AFNetworking이 약간의 간섭을 일으키는 것 같은 느낌이 들지만 처음 iOS 개발자로서 무엇이 문제인지 확신 할 수 없다. 그래도 고마워! :) @Shmidt – GangstaGraham
dispatch_sync를 dispatch_sync로 바꾸어보세요. – Shmidt