UIWebView加载本地文件

时间:2010-06-21 05:42:34

标签: iphone uiwebview

我已尝试过许多线程中指定的许多方式。我的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无法正常工作。有人可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

确保将Javascript文件复制到资源包。将.js文件添加到Xcode时,它会尝试默认编译它们,而不是将它们复制到资源包中。有关详细信息,请参阅jQuery not loading on the iPhone