如何使用UIWebview显示本地存储的图像

时间:2010-01-31 08:24:43

标签: iphone uiwebview

连接时:
我有一个简单的HTML页面,其中包含一些图像元素,这些图像元素引用子目录中的图像,如(src =“images / someimage.jpg”)。通过互联网连接远程访问时,此页面显示正常。

离线时:
我将上述HTML页面本地存储到apps文档目录以供离线查看。使用UIWebView加载并显示本地HTML页面 - 问题是HTML文件中的图像显示为 NOT

可能的原因:
我想问题可能是图像路径(<img src="photo_files/..." />)没有在本地解析为绝对路径?如何获取它以便我可以在UIWebView中显示本地图像而无需修改html源代码?我不想进入那里并手动将每个图像路径更改为文档目录路径...如何在UIWebView上正确显示本地图像?

问题:
如何获取它以便我可以在UIWebView中显示本地图像而无需修改html源?

(假设有效的本地路径... / Photos / photos.html,以及照片/ photo_files /(图像文件).jpg全部位于文档目录路径下)

HTML网页来源

...

<html>
<body>

<h1>Photo Gallery</h1>


<img src="photo_files/app_IMG_01.jpg" /><br />
<img src="photo_files/app_IMG_0100.jpg" /><br />
<img src="photo_files/app_IMG_0066.jpg" /><br />


</body>
</html>

Objective-C来源

...

    NSFileManager* myManager = [NSFileManager defaultManager];  

    if([myManager fileExistsAtPath:[[self documentsDirectory] stringByAppendingPathComponent:@"/Photos/photos.html"]]){

        NSLog(@"Loading Saved Copy!");
        urlAddress = [[self documentsDirectory] stringByAppendingPathComponent:@"/Photos/photos.html"];


        //Create a URL object.
        NSURL *url = [NSURL fileURLWithPath:[[self documentsDirectory] stringByAppendingPathComponent:@"/Photos/photos.html"] isDirectory:NO];
        //URL Requst Object
        NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
        //Load the request in the UIWebView.
        [webView loadRequest:requestObj];

1 个答案:

答案 0 :(得分:0)

我发现为什么这不适合我。它与完全不同的东西有关。 UIWebView似乎没有相对路径的任何问题。

相关问题