UIWebView:应用程序文档文件夹中图像的绝对路径
问题描述:
我有一个加载了一些html的UIWebView。在它是一个img标签,我保存在应用程序的文档文件夹中的图片,我想在HTML中显示的图像,我这样做是这样UIWebView:应用程序文档文件夹中图像的绝对路径
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
NSString *tempImgFN = [NSString stringWithFormat:@"tempImg%d.jpg",storyRowID];
NSString *tempImg = [documentsDir stringByAppendingPathComponent:tempImgFN];
[imageBlob writeToFile:tempImg atomically:NO];
tempImg = [tempImg stringByReplacingOccurrencesOfString:@"/" withString:@"//"];
tempImg = [tempImg stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
[string appendString:[NSString stringWithFormat:@"<img style='max-width:120px' src=\"%@\" alt=\"\"/>",tempImg]];
的imageBlob是一个NSData与该数据图片。图像被成功保存,其余的html加载正常,但图像不显示。
如果我将UIwebView的baseUrl设置为指向文档文件夹,此工作正常。但我不想这样做,因为我希望baseURL是[NSBundle mainBundle] resourcePath]来访问一些JavaScript文件和css
答
woops那是愚蠢的我..只需要把src = \“文件:/%@ \“
如果你不介意澄清一下:'file:/%@'返回什么?它应该返回index.html所在的相对路径吗?在我的情况下,你的建议会返回:'file:///%@' – sAguinaga 2014-01-02 10:14:59