0

我有点卡住了,...

我已经编写了我的应用程序,现在我只需要一个按钮来打开我的应用程序资源文件夹中的 HTML 文档。

因此,如果您单击按钮,html 文件将在新窗口或 safari 中打开。不管那是最简单的方法。

谁能帮助我?

4

2 回答 2

0

干得好:

NSString *path = [[NSBundle mainBundle] pathForResource:@"your file name" ofType:@"html"];
NSURL *baseURL = [[NSURL alloc] initFileURLWithPath:path isDirectory:YES];
NSString *html = [NSString stringWithContentsOfURL:[NSURL fileURLWithPath:path]  encoding:NSUTF8StringEncoding error:nil];
[webview setDelegate:self];
webview.dataDetectorTypes = UIDataDetectorTypeAll;
[webview loadHTMLString:html baseURL:baseURL];
于 2013-03-09T20:02:31.003 回答
0

您需要从路径中读取文件。

如果它在资源文件夹(即 NSBundle)中,则可以,否则获取路径。

阅读html并显示它。

你可以通过两种方式做到这一点,第二种方式是使用 NSAppleScript,这对沙盒应用程序不利。

第一种方法是在 webView 中显示它。

NSString *path=[[NSBundle mainBundle] pathForResource:@"index" 
                                               ofType:@"html"/*or htm as per your file extension*/
                                          inDirectory:@"yourDirectoryName"];
NSURL *url=[NSURL fileURLWithPath:path];
NSURLRequest *urlRequest=[NSURLRequest requestWithURL:url];
[[webView mainFrame] loadRequest:urlRequest];
于 2013-03-09T19:27:51.777 回答