ios如何加载本地文件

如题所述

1,本地的html文件一定要放到工程文件的根目录

2,html代码中的图片路径一定要是相对路径

3,下面是用UIWebView调用本地文件的方法

方法一:

NSString *filePath = [[NSBundle mainBundle]pathForResource:@"1" ofType:@"html"];

NSString *htmlString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil]

[myWebView loadHTMLString:htmlString baseURL:[NSURL URLWithString:filePath]];

方法二:

NSString *filePath = [[NSBundle mainBundle]pathForResource:@"1" ofType:@"html"];

NSURL *url = [NSURL fileURLWithPath:filePath];

NSURLRequest *request = [NSURLRequest requestWithURL:url];

[myWebView loadRequest:request];

[self.view addSubview:myWebView];
温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-01-22
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"plistdemo" ofType:@"plist"];
NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
NSLog(@"%@", data);//直接打印数据。

上面为plist文件读取示例

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网