Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am new to iPhone App development.

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 -

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

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

The code I used for getting images from url is -

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.

like image 687
nbs Avatar asked Nov 08 '12 10:11

nbs


2 Answers

I think you are using NSString as NSURL. Try this:

    NSURL *imageUrl =[NSURL URLWithString:[attributeDict objectForKey:@"url"]];
like image 137
Ramaraj T Avatar answered Sep 21 '22 12:09

Ramaraj T


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

if ([elementName isEqualToString:IMAGE])
{
    NSString *urlStr = [attributeDict objectForKey:@"url"];
    NSURL *imageUrl = [NSURL URLWithString:urlStr];
    NSData *imageData = [NSData dataWithContentsOfURL:imageUrl];
    bbc.image = [UIImage imageWithData:imageData];        
}
like image 33
trojanfoe Avatar answered Sep 24 '22 12:09

trojanfoe