我在文件目录中的文件夹中有一个文件夹我有main.html页面我想在webview中打开那个html页面可以提供帮助吗?
答案 0 :(得分:1)
试试这个。
//First get the path of the documents directory
NSString *documentsDirectoryPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"main.html"];
//Load webview
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@", documentsDirectoryPath];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webviewForHelp loadRequest:request];
答案 1 :(得分:0)
获取DocumentDirectory
路径并将main.html
追加到该路径。
NSString *documentPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"main.html"];
然后使用
加载它NSURL* address = [NSURL fileURLWithPath:documentPath];
NSURLRequest* request = [NSURLRequest requestWithURL:address] ;
[webView loadRequest:request];
答案 2 :(得分:0)
NSString *htmlFilePath = [[NSBundle mainBundle]pathForResource:@"main" ofType:@"html"];
NSString* htmlString = [NSString stringWithContentsOfFile:htmlFilePath encoding:NSUTF8StringEncoding error:nil];
[webView loadHTMLString:htmlString baseURL:nil];