简体   繁体   English

在iPhone上的UIWebView中显示文档目录中的本地HTML文件

[英]Display Local HTML file from documents directory in a UIWebView on iPhone

How can I display a HTML file from the Documents directory in my app? 如何在应用程序的“文档”目录中显示HTML文件? Below is the code that I'm using and nothing is showing up in my UIWebView 下面是我正在使用的代码,但UIWebView没有任何显示

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory, @"Notes.html"];

    NSURL *url = [NSURL URLWithString:filePath];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [notesListWeb loadRequest:request];

Why is this not working out? 为什么这不起作用?

I've found other answers but they aren't from the documents directory. 我找到了其他答案,但是它们不是来自documents目录。

Your help is greatly appreciated. 非常感谢您的帮助。

The proper way to create an NSURL object with a file path is: 创建带有文件路径的NSURL对象的正确方法是:

NSURL *url = [NSURL fileURLWithPath:filePath];

You should also change how you create your filePath : 您还应该更改创建filePath的方式

NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"Notes.html"];

Also keep in mind that filenames are case sensitive on a real iOS device. 另外请记住,文件名在真实的iOS设备上区分大小写。 Is the file really named Notes.html and notes.html? 该文件是否真正命名为Notes.html和notes.html?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM