Ios UIWebView使用cocos2d js animaiton加载本地html
我有一些关于UIWebView的问题,使用cocos2d js Animation加载本地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
| -> 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];
希望有帮助