xcode NSInvalidArgumentException',原因:'-[__NSCFString isFileURL]:无法识别的选择器发送到实例 0x712e450'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13287587/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 02:02:41  来源:igfitidea点击:

NSInvalidArgumentException', reason: '-[__NSCFString isFileURL]: unrecognized selector sent to instance 0x712e450'

objective-ciosxcodeios5ios4

提问by nbs

I am new to iPhone App development.

我是 iPhone 应用程序开发的新手。

When I run a sample project, I did which parses an xmlfeed and displays the contents along with image in a table view, I get this error -

当我运行一个示例项目时,我解析了一个xml提要并在表格视图中显示内容和图像,我收到这个错误 -

"NSInvalidArgumentException', reason: '-[__NSCFString isFileURL]: unrecognized selector sent to instance 0x712e450'"

It is occurring only when I try to display the image in UITableViewCell.

仅当我尝试在UITableViewCell.

The code I used for getting images from urlis -

我用来获取图像的代码url是 -

if([elementName isEqualToString:IMAGE])
{
    NSURL *imageUrl = [attributeDict objectForKey:@"url"];
    NSData *imageData = [NSData dataWithContentsOfURL:imageUrl];
    bbc.image = [UIImage imageWithData:imageData];        
}

where bbcis a class(NSObject subclass)object used to store the parsed contents.

其中bbcclass(NSObject subclass)用于存储解析内容的对象。

回答by Ramaraj T

I think you are using NSStringas NSURL. Try this:

我认为您正在使用NSStringas NSURL。尝试这个:

    NSURL *imageUrl =[NSURL URLWithString:[attributeDict objectForKey:@"url"]];

回答by trojanfoe

It looks like "url" is in fact an NSString, not an NSURLobject. Convert it to an NSURLobject yourself:

看起来“url”实际上是一个NSString,而不是一个NSURL对象。NSURL自己将其转换为对象:

if ([elementName isEqualToString:IMAGE])
{
    NSString *urlStr = [attributeDict objectForKey:@"url"];
    NSURL *imageUrl = [NSURL URLWithString:urlStr];
    NSData *imageData = [NSData dataWithContentsOfURL:imageUrl];
    bbc.image = [UIImage imageWithData:imageData];        
}

回答by Ramy Al Zuhouri

imageURL is not a NSURL, but a string.

imageURL 不是 NSURL,而是一个字符串。