2014-03-07 72 views
0

我一直在嘗試加載保存的網頁,而不直接將文件添加到項目中。 我一直在嘗試這樣的事情:從本地路徑加載網頁iOS

NSString *urlAddress = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"/Users/Virtual-OSX/Desktop/website/files"]; 
NSURL *url = [NSURL fileURLWithPath:urlAddress]; 
NSURLRequest * requestObj = [NSURLRequest requestWithURL:url]; 
[webView loadRequest:requestObj]; 

沒有被發現urlAddress任何人都可以在這方面幫助。就像我說過的,我想避免將文件拖入項目中。

塗料...找到我的答案後,我停止閱讀,並試圖嘗試,我發現我可以讓

NSString *urlAddress = /Users/Virtual-OSX/Desktop/website/files/index.html 
+0

你可以檢查你給出的路徑..是正確的..路徑顯示文件加載桌面..它不是從捆綁..試圖檢查文件存在的路徑.. – RAJA

+0

感謝您的反饋..路徑是正確的,但我只需要讓字符串等於路徑不需要任何東西:) – user3024457

回答

0
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"]; 
NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil]; 
[webView loadHTMLString:htmlString baseURL:nil];