开发者

How to load an local HTML file as string into UIWebView?

I'd like to use UIWebView's - (void)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL

but I'm not sure what this baseURL is good for or how I would create that. My file is called localHTMLfile.html and I know how I would load this file the normal way:

NSURL *url = [[NSBundle mainBundle] URLForResource:@"localHTMLfile" withExtension:@"html"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webview loadRequest:request];

So it's just a raw guess, but开发者_运维技巧 would that baseURL be the NSURL object I've created already? Does that make sense?


The whole point of a UIWebView is to show a web page. Therefore the base URL will be the path where relative links in the HTML document will point to.

If you're showing http://mywebpage.com/this/that/foo/bar.html then your base URL will be the base URL of that page - wherever relative links and such are pointing to. Its so that any links eg <a href="../hello.html">This is a link</a> will be pointed to reliably.

For you I guess you could do: [NSURL URLWithString:[[NSBundle mainBundle] bundlePath]]


baseURL would be a file: URL that points to the directory the local HTML file is stored in. It will be used to convert any relative paths in the HTML file (e.g. references to CSS or image files) to their absolute locations.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜