nbs
nbs

Reputation: 573

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.

Upvotes: 11

Views: 16569

Answers (3)

Ramaraj T
Ramaraj T

Reputation: 5230

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

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

Upvotes: 31

Ramy Al Zuhouri
Ramy Al Zuhouri

Reputation: 21986

imageURL is not a NSURL, but a string.

Upvotes: 1

trojanfoe
trojanfoe

Reputation: 122401

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];        
}

Upvotes: 1

Related Questions