Objective c NSData initWithContentsOfURL错误

Objective c NSData initWithContentsOfURL错误,objective-c,nsdata,nsurl,cs193p,Objective C,Nsdata,Nsurl,Cs193p,我正在尝试从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] *** Terminati

我正在尝试从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的一个示例:

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方法有什么问题?谢谢
谢谢

imageUrl
可以定义为
NSURL
属性,但您已将其值设置为
NSString
实例。在许多情况下,这可能不会给您编译器警告,并且在您尝试使用它之前不会引发异常


检查设置
imageUrl
的位置,确保验证类型并创建
NSURL

“当然self.imageUrl是NSURL属性。”不,不是。根据错误,这是一个NSCFString。您需要从字符串创建URL。谢谢,错误是我设置属性的地方,因为我传递的是字符串而不是NSURL:NSURL*URL=[[photo.photoURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];如果我将此方法更改为:NSURL*url=[NSURL URLWithString:[photo.photoURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];很好。感谢并为愚蠢的错误感到抱歉XD。