[英]NSInvalidArgumentException', reason: '-[__NSCFString isFileURL]: unrecognized selector sent to instance 0x712e450'
I am new to iPhone App development. 我是iPhone App开发的新手。
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)
对象。
I think you are using NSString
as NSURL
. 我认为你使用
NSString
作为NSURL
。 Try this: 试试这个:
NSURL *imageUrl =[NSURL URLWithString:[attributeDict objectForKey:@"url"]];
It looks like "url" is in fact an NSString
, not an NSURL
object. 看起来“url”实际上是
NSString
,而不是NSURL
对象。 Convert it to an NSURL
object yourself: 自己将其转换为
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];
}
imageURL不是NSURL,而是字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.