通常我的应用程序使用以下代码调用html文件:
- (IBAction)loadLocalFile:(id)sender
{
UIButton *tmp = sender;
int tag = tmp.tag;
NSString *fileName = [NSString stringWithFormat:@"dossier%i", tag];
NSURL *url = [NSURL URLWithString:@""];
NSString *filePath = @"";
switch (tag) {
case 1:
{
filePath = [[NSBundle mainBundle] pathForResource:fileName ofType:@"html"];
break;
}
case 2:
{
filePath = [[NSBundle mainBundle] pathForResource:fileName ofType:@"html"];
break;
}
case 3:
{
filePath = [[NSBundle mainBundle] pathForResource:fileName ofType:@"html"];
break;
}
default:
break;
}
url = [NSURL fileURLWithPath:filePath];
LocalViewController *vc = [[LocalViewController alloc] initWithNibName:@"LocalViewController" bundle:nil url:url];
[self.navigationController pushViewController:vc animated:YES];
}
如何修改上面的代码,使其在documentsDir
中查找,如果解压缩的文件在那里,请打开一个而不是应用程序包中的那个。
答案 0 :(得分:1)
如果您想使用名称filePath
的文件路径设置fileName
,您可以使用以下内容:
NSString *documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
NSString *filePath = [documentsPath stringByAppendingPathComponent:fileName];