Web から画像を読み込もうとしています。データを初期化するには、次のメソッドを使用します。
NSData *imageData = [[NSData alloc] initWithContentsOfURL:self.imageUrl];
しかし、私はこのエラーが発生します:
[__NSCFString isFileURL]: unrecognized selector sent to instance 0x817a4f0
2013-08-26 09:45:53.221 CorePhoto[1643:3f03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString isFileURL]: unrecognized selector sent to instance 0x817a4f0'
もちろん、self.imageUrl は NSURL プロパティです。
これは imageUrl url の例です。
http://farm5.static.flickr.com/4016/4555417946_e6332481b3_b.jpg
これは私のメソッドの完全なコードです:
- (void)resetImage
{
if (self.scrollView) {
if (self.imageUrl) {
//before to set the content, we reset it
self.scrollView.contentSize = CGSizeZero;
self.imageView.image = nil;
[self.spinner startAnimating];
dispatch_queue_t loadImageQ = dispatch_queue_create("load image thread", NULL);
dispatch_async(loadImageQ, ^(void) {
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
NSData *imageData = [[NSData alloc] initWithContentsOfURL:self.imageUrl];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
UIImage *image = [[UIImage alloc] initWithData:imageData];
dispatch_async(dispatch_get_main_queue(), ^(void) {
if (image) {
self.scrollView.zoomScale = 1.0;
self.scrollView.contentSize = image.size;
self.imageView.image = image;
self.imageView.frame = CGRectMake(0, 0, image.size.width, image.size.height);
}
[self.spinner stopAnimating];
});
});
}
}
}
initWithContentsOfURL メソッドの何が問題になっていますか? どうもどうも