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
NSInvalidArgumentException', reason: '-[__NSCFString isFileURL]: unrecognized selector sent to instance 0x712e450'
提问by nbs
I am new to iPhone App development.
我是 iPhone 应用程序开发的新手。
When I run a sample project, I did which parses an xml
feed 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 url
is -
我用来获取图像的代码url
是 -
if([elementName isEqualToString:IMAGE])
{
NSURL *imageUrl = [attributeDict objectForKey:@"url"];
NSData *imageData = [NSData dataWithContentsOfURL:imageUrl];
bbc.image = [UIImage imageWithData:imageData];
}
where bbc
is a class(NSObject subclass)
object used to store the parsed contents.
其中bbc
是class(NSObject subclass)
用于存储解析内容的对象。
回答by Ramaraj T
I think you are using NSString
as NSURL
. Try this:
我认为您正在使用NSString
as NSURL
。尝试这个:
NSURL *imageUrl =[NSURL URLWithString:[attributeDict objectForKey:@"url"]];
回答by trojanfoe
It looks like "url" is in fact an NSString
, not an NSURL
object. Convert it to an NSURL
object 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,而是一个字符串。