ios如何加载本地文件
答案:2 悬赏:30 手机版
解决时间 2021-04-08 00:55
- 提问者网友:斑駁影
- 2021-04-07 11:47
ios如何加载本地文件
最佳答案
- 五星知识达人网友:酒者煙囻
- 2021-04-07 13:18
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];
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楼网友:一把行者刀
- 2021-04-07 14:50
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"plistdemo" ofType:@"plist"];
NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
NSLog(@"%@", data);//直接打印数据。
上面为plist文件读取示例
NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
NSLog(@"%@", data);//直接打印数据。
上面为plist文件读取示例
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯