UIImageView
画像の非同期読み込みを可能にするためのカテゴリを作成しました。
@implementation UIImageView (ImageLoader)
- (void) asyncLoadImageIntoView:(NSURL *)imageURL withLoadingIndicator:(BOOL)isLoadingIndicator {
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:imageURL cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60];
(void)[[NSURLConnection alloc] initWithRequest:request delegate:self];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
// responseData = [[NSMutableData alloc] init];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
NSLog(@"didReceiveData %@", data);
(void)[self.image initWithData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
//[textView setString:@"Unable to fetch data"];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"Succeeded! Received image data");
}
@end
私の問題は、connection:didReceiveData:
メソッドが呼び出されてデータがコンソールに出力[self.image initWithData:data]
されても、ビューに画像が読み込まれていないように見えることです。ここでの問題は何ですか?