Search code examples
iphonensurl

NSURL URLWithString: giving nil


Please see the below code :

UIImage *image;
NSString *str = [[[Data getInstance]arrPic]objectAtIndex:rowIndex];
NSLog(str);
NSURL *url = [NSURL URLWithString:str];
NSData *data = [NSData dataWithContentsOfURL:url];
image = [UIImage imageWithData:data];  

str is giving me http://MyDomain/Pics\\1.png but url is giving me nil.


Solution

  • Just try using this,

    [NSURL URLWithString:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];