Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.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 UIWebView使用cocos2d js animaiton加载本地html_Ios_Objective C_Uiwebview_Cocos2d Js - Fatal编程技术网

Ios UIWebView使用cocos2d js animaiton加载本地html

Ios UIWebView使用cocos2d js animaiton加载本地html,ios,objective-c,uiwebview,cocos2d-js,Ios,Objective C,Uiwebview,Cocos2d Js,我有一些关于UIWebView的问题,使用cocos2d js Animation加载本地html。 事情是这样的: 文件夹的结构类似于: 资源 | -> www |->1 | -> 1.html,1.js | -> res | -> Cowboy.ExportJson,Cowboy.plist,Cowboy.png 。当我在xcod

我有一些关于UIWebView的问题,使用cocos2d js Animation加载本地html。 事情是这样的: 文件夹的结构类似于:

资源

 | -> www

          |->1
               | -> 1.html,1.js
               | -> res
                        | -> Cowboy.ExportJson,Cowboy.plist,Cowboy.png
。当我在xcode项目中拖动文件夹时,我选择创建文件夹引用

我想加载1.html,它会调用1.js然后显示动画,但是牛仔资源无法成功加载,我 以下是代码:

我发现了一个异常,比如没有获取资源

我尝试了3种加载到我的webView的方法:

NSURL *url = [[NSBundle mainBundle] URLForResource:@"www/1/1" withExtension:@"html"];
NSString *html = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
NSLog(@"%@",[url URLByDeletingLastPathComponent]);
[self.webView loadHTMLString:html baseURL:[url URLByDeletingLastPathComponent]];


NSURL *requestUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"1" ofType:@"html" inDirectory:@"www/1"]];
[self.webView loadRequest:[NSURLRequest requestWithURL:requestUrl]];


 NSURL *url = [[NSBundle mainBundle] URLForResource:@"www/1/1" withExtension:@"html"];
NSString *html = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
NSString *baseURL = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"www/1"];   self.webView loadHTMLString:html baseURL:[NSURL fileURLWithPath:baseURL]];

我相信他们没用。谁能帮我。谢谢

首先,检查目标构建阶段->复制捆绑资源

其次,我认为它应该是NSString*htmlFile=[[NSBundle mainBundle]pathForResource:@1 of type:@html]

第三,使用stringWithContentsOfFile而不是stringWithContentsOfURL

应该是这样的-

NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"1" ofType:@"html"];
NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
[webView loadHTMLString:htmlString baseURL:nil];
希望有帮助