如何打开文档目录中的Html页面?

时间:2012-12-14 11:47:58

标签: objective-c ios xcode

我在文件目录中的文件夹中有一个文件夹我有main.html页面我想在webview中打开那个html页面可以提供帮助吗?

3 个答案:

答案 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];