Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.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
Iphone UIWebView加载本地文件_Iphone_Uiwebview - Fatal编程技术网

Iphone UIWebView加载本地文件

Iphone UIWebView加载本地文件,iphone,uiwebview,Iphone,Uiwebview,我尝试了许多线程中指定的方法。我的WebView仍然没有加载本地js文件。 我试过的方法 NSString *tempResourcePath=[[NSBundle mainBundle] resourcePath]; NSURL *resourceUrl = [NSURL fileURLWithPath:tempResourcePath]; [webView loadHTMLString:html baseURL:resourceUrl]; NSString *html = [[NSStr

我尝试了许多线程中指定的方法。我的WebView仍然没有加载本地js文件。 我试过的方法

NSString *tempResourcePath=[[NSBundle mainBundle] resourcePath];
NSURL *resourceUrl = [NSURL fileURLWithPath:tempResourcePath];
[webView loadHTMLString:html baseURL:resourceUrl];


NSString *html = [[NSString alloc] initWithContentsOfFile:htmlPath];
    NSString *resourcePath = [[NSBundle mainBundle] resourcePath];
    //resourcePath = [resourcePath stringByReplacingOccurrencesOfString:@"/" withString:@"//"];
    resourcePath = [resourcePath stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
    resourcePath = [NSString stringWithFormat:@"file:/%@/",resourcePath];
 NSURL *resourceUrl = [NSURL fileURLWithPath: resourcePath];

但是webview不起作用。有人能帮我解决这个问题吗?

确保Javascript文件被复制到资源包中。当您将.js文件添加到Xcode时,默认情况下它会尝试编译它们,而不是将它们复制到资源包中。有关详细信息,请参阅