我使用web视图加载存储在我的应用程序库目录中的图像文件,首先我想利用resourcePath,并捆绑路径加载图像失败
NSString * html = [[NSString alloc] initWithFormat:@"<img src=\"file://%@\"/>", filename];
[self.webView loadHTMLString:newhtml baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] resourcePath]]];
问题是不管我的设置的baseUrl,我无法正确加载图像,我也尝试过文件路径:
[self.webView loadHTMLString:newhtml baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] filePath]]];
,但如果我在HTML设置图像文件的绝对路径,所有的事情就可以了,我不知道为什么?
提示:NSLog的结果HTML字符串,看看为什么。 – magma
我得到了错误的文件名在html ..这是好的,如果我把图像目录正确地进入baseURL: NSArray * paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,YES); NSString * path = [paths objectAtIndex:0]; path = [path stringByAppendingPathComponent:@“/ ImageCache”]; – zolibra