转自:http://www.cocoachina.com/bbs/read.php?tid-21900.html
- (void)loadDocument:(NSString*)docName {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:docName];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
self.myWebView.scalesPageToFit = YES;
[self.myWebView loadRequest:request];
}
这个函数是加载Documents里边的文件,如果是你App内部的,需要改一下代码
NSString *mainBundleDirectory = [[NSBundle mainBundle] bundlePath];
NSString *path = [mainBundleDirectory stringByAppendingPathComponent:docName];
本文介绍了一个用于将本地Documents目录中的文件加载到iOS应用内的WebView中的方法。通过修改路径指向App内部资源的方式,实现了不同场景下文件的有效加载。
1万+

被折叠的 条评论
为什么被折叠?



