顯示本地存儲的圖像在連接時:
我有與該參考圖像中的子目錄如(SRC =「圖像/ someimage.jpg」)的一些圖像元素的簡單的HTML頁面。通過互聯網連接遠程訪問時,此頁面顯示正常。如何與一個UIWebView
脫機時:
我在本地存儲上面的HTML頁面進行離線觀看的應用程序文件目錄。使用UIWebView加載並顯示本地HTML頁面 - 問題在於HTML文件中的圖像顯示爲NOT。
可能的原因:
我想這個問題可能是成像路徑(<img src="photo_files/..." />
)得不到解決,以絕對路徑在本地?我如何獲得它,以便我可以在UIWebView中顯示本地圖像而無需修改html源代碼?我不想在那裏去手動更改每個圖像路徑到文檔目錄路徑...我如何讓本地圖像在我的UIWebView上正確顯示?
問:
我如何得到它,這樣我可以在不修改HTML源代碼顯示在一個UIWebView本地圖片?
(假設有效的本地路徑... /圖片/ 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];
查看http://stackoverflow.com/questions/1053288/displaying-an-image-in-uiwebview – kennytm 2010-01-31 08:30:08