UIWebView loadHTMLString not working in iOS5

后端 未结 2 1222
心在旅途
心在旅途 2021-02-05 15:10

Perhaps this is similar to this question, which has no responses: loadHTMLString Not Working With iOS5?

I have a UIWebView which I populate using loadHTMLString:baseURL

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-05 15:51

    The way to load an HTML file that contains embedded folder references, such as '/file.js', is to load it as a URL rather than as a STRING.

    NSString *urlAddress = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"htm"];
    NSURL *url = [NSURL fileURLWithPath:urlAddress];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    [webView loadRequest:requestObj];
    

    I use this along with referenced folders (not referenced files) to create an ordinary website structure in Xcode, with js/ and css/ and images/ references in the embedded index.htm file, e.g.

    
    

    UPDATE

    I don't think that referencing a URI within a loaded HTML string was officially supported. If you must use a string, then load the needed resource files into the string before you load it into the UIWebView.

提交回复
热议问题