iphone 项目中如何加载本地html文件到uiwebview
-
( 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]; } |
上面的参数docName换成要加载的html的文件名吗?包括后缀名?按你的方法试了下还是没加载好,
不知什么原因
我这个函数是加载Documents里边的文件,如果是你App内部的,需要改一下代码
NSString *mainBundleDirectory = [[NSBundle mainBundle] bundlePath];
NSString *path = [mainBundleDirectory stringByAppendingPathComponent:docName];