2014-11-05 65 views
2

Stucked on加載下面的本地路徑url UIWebview。在spinepath中找到url,然後我轉換爲url [Spin​​ePathUrl]。無法在UIWebview中加載Url,#轉換爲%23

我的問題是,當我嘗試加載時,我得到零值。 爲了檢查的目的,我粘貼SpinepathUrl到瀏覽器,它顯示的網頁不found.Then,我改變SpinePathUrl 「arugoswami-4.xhtml%23toc_marker-4」「arugoswami-4.xhtml#toc_marker-4」,其顯示結果。

是我的問題在網址中。爲什麼#轉換爲%23,當它從String轉換爲Url時。

spinepath = [NSString stringWithFormat:@"%@%@",documentsDirectory,Path]; 
spinepath = [spinepath stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; 
spinepath = [spinepath stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 

[/用戶/ blazedream /庫/應用程序支持/ iPhone模擬器/ 7.1 /應用/ E19D2CD0-E0DC-460E-8BC9-97A9C8010910 /文檔/ UnzippedEpub/OEBPS/arugoswami-4.xhtml#toc_marker -4]

NSURL *SpinePathUrl = [NSURL fileURLWithPath:spinepath]; 

[文件:///Users/blazedream/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/E19D2CD0-E0DC-460E-8BC9-97A9C8010910/Documents/UnzippedEpub/OEBPS/arugoswami-4.xhtml%23toc_marker-4]

NSURLRequest *request = [NSURLRequest requestWithURL:SpinePathUrl]; 
[webView loadRequest:request]; 
+0

請清除您的問題 – gran33 2014-11-05 09:48:58

+0

你因此未明白嗎?/ – Ramdy 2014-11-05 09:55:31

+0

沒有隊友,u能請註明問題和問題? – gran33 2014-11-05 09:57:07

回答

3

嘗試增加片段手動

NSURL *baseUrl = [NSURL fileURLWithPath:@"... arugoswami-4.xhtml"]; 
NSURL *fullURL = [NSURL URLWithString:@"#toc_marker-4" relativeToURL:baseUrl]; 
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:fullURL]; 

[myWebView loadRequest:urlRequest]; 
+0

感謝您的回覆,請稍等我試試 – Ramdy 2014-11-05 10:15:39

+0

好點,謝謝:D – Claudio 2017-06-28 15:03:57