iphone - Get image from XML url and load into UITableView -


i ran problem , try solve it. in method:

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { 

i wrote:

nsmutablestring *urlxml = [nsmutablestring stringwithformat:@"%@", [[elencofeed objectatindex:indexpath.row]objectforkey:@"img"]]; nsmutabledata *imagedata = [[nsdata alloc] initwithcontentsofurl:[nsurl urlwithstring:urlxml]]; nslog(@"imgdata: %@",imagedata); 

the xml written as:

<img>http://site/blu.png</img> 

but problem "urlxml" responds url inside xml tag "imagedata", responds log "(null) ".

what put inside of uitableview image each row. wrong?

try trimming , escaping urlxml string this:

// assuming returns string valid url (taken question) nsstring *urlxml = [nsmutablestring stringwithformat:@"%@", [[elencofeed objectatindex:indexpath.row]objectforkey:@"img"]]; // reading @filippo's comments looks string returned contains trailing tabs , line breaks, let's trim nsstring *trimmed = [urlxml stringbytrimmingcharactersinset:[nscharacterset whitespaceandnewlinecharacterset]]; nsurl *url = [nsurl urlwithstring:[trimmed stringbyaddingpercentescapesusingencoding:nsutf8stringencoding]]; nserror *error = nil; nsdata *imagedata = [[nsdata alloc] initwithcontentsofurl:url options:0 error:&error]; if (error) {     nslog(@"error %@, %@", error, [error userinfo]); } 

Comments