크기가 320 X 200 인 UIImageView가있는 셀을 포함하는 UITableView를 사용하는 앱을 개발 중입니다. 이 이미지는 웹 URL에서 가져 와서 내 앱 폴더에 저장합니다. 사용자에게.셀에 이미지가있는 UITableView
"UIImageView + AFNetworking.h"클래스의 아래 메서드를 사용하고 있습니다.
- (void)setImageWithURL:(NSString *)url
placeholderImageName:(NSString *)placeholderImage
saveFilePath:(NSString *) filePath
IndexPath:(NSIndexPath *)indexPath
success:(void (^)(NSIndexPath *indexPath, UIImage *image))success
failure:(void (^)(NSIndexPath *indexPath, NSError *error))failure {
NSLog(@"DOWNLOAD IMG URL :: %@", url);
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
[request setHTTPShouldHandleCookies:NO];
[request setHTTPShouldUsePipelining:YES];
[request addValue:@"image/*" forHTTPHeaderField:@"Accept"];
[self setImageWithURLRequest:request
placeholderImage:placeholderImage == nil? nil : [UIImage imageNamed:placeholderImage]
success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
[Storage SaveImage:image WithFileName:filePath];
if (success)
success(indexPath, image);
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
if (failure)
failure(indexPath, error);
}
];
}
이미지를 표시하는 동안 내 모든 이미지가 내 로컬 폴더에 다운로드되면 내 tableview가 멈추었습니다.
그것은 당신이 메인 스레드에서 이미지를 저장하는 날 것으로 보인다. 여기 : [Storage SaveImage : image WithFileName : filePath]; – Ricardo
이 라이브러리를 사용하여 이미지를 다운로드하고 UItableview https://github.com/rs/SDWebImage – nivritgupta