Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何加载作为项目一部分的HTML5文档?_Ios_Xcode - Fatal编程技术网

Ios 如何加载作为项目一部分的HTML5文档?

Ios 如何加载作为项目一部分的HTML5文档?,ios,xcode,Ios,Xcode,我正在开发一个iPhone应用程序,在我的项目中,我添加了一个HTML5页面,它是一个模板,有一个webview,并希望将其加载到viewdidload上。我似乎无法访问它,我正在尝试: NSArray *documentDirectories = NSSearchPathForDirectoriesInDomains( NSAllApplicationsDirectory, NSUserDomainMask, YES ) ; NSString *documentDirectory =

我正在开发一个iPhone应用程序,在我的项目中,我添加了一个HTML5页面,它是一个模板,有一个webview,并希望将其加载到viewdidload上。我似乎无法访问它,我正在尝试:

NSArray *documentDirectories = NSSearchPathForDirectoriesInDomains(    NSAllApplicationsDirectory, NSUserDomainMask, YES ) ;

NSString *documentDirectory =  [ documentDirectories objectAtIndex: 0 ] ;
    NSString *longPath = [ documentDirectory stringByAppendingFormat:@"/%@" filename ] ;
我有点困惑?我怎样才能做到这一点?我需要告诉xcode这个html5需要在运行时构建并发送到一个特定的文件夹吗?就像被当作资源一样

我是来自.NET环境的xcode新手,所以这个术语可能有点笨拙


谢谢

如果它是项目的一部分,它将不在文档目录中,而是在您的应用程序包中。例如:

NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:filename ofType:@"html"]];
NSURLRequest *req = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:req];

html文件在捆绑包或文档目录中的哪个位置?html文件与viewcontroller处于同一级别。我正在执行以下操作:NSString*文件名=[NSString stringWithFormat:@“sampleHTML.html”];NSURL*url=[NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:文件名类型:@“html”目录:@“html”];NSURLRequest*req=[nsurlRequestRequestWithURL:url];[self.webView加载请求:req];仍然没有什么,我无法加载html文件,我得到一个错误:[NSURL initFileURLWithPath:]:nil string参数'得到它,我需要使用不带扩展名的文件名,因此NSURL*url=[NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@“sampleHTML”类型:@“html”];