2014-11-05 146 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