这就是我解决它的方法。我还没有使用缓存,但这足以在 UITableViewCell 中正确显示它们。这是我使用的方法。
+ (void)downloadImageWithURL:(NSMutableURLRequest *)request completionBlock:(void (^)(BOOL succeeded, UIImage *image))completionBlock
{
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;
int statusCode = httpResponse.statusCode ;
NSLog(@"Status Code Imageloading : %d" , statusCode);
if(statusCode == 200){
UIImage *image = [[UIImage alloc] initWithData:data];
NSLog(@"Success");
completionBlock(YES,image);
} else {
NSLog(@"Failure");
completionBlock(NO,nil);
}
}];
}