0

我在该文件夹中的文档目录中有一个文件夹我有 main.html 页面我想在 webview 中打开该 html 页面有人可以帮忙吗?

4

3 回答 3

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];
于 2012-12-14T11:53:43.307 回答
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];
于 2012-12-14T11:56:09.663 回答
0
 NSString *htmlFilePath = [[NSBundle mainBundle]pathForResource:@"main" ofType:@"html"];

 NSString* htmlString = [NSString stringWithContentsOfFile:htmlFilePath encoding:NSUTF8StringEncoding error:nil];
    [webView loadHTMLString:htmlString baseURL:nil];
于 2012-12-14T12:03:32.890 回答