loadHTMLString baseURL:nil在iOS5中不起作用

moo*_*oon 6 xcode uiwebview ios5

我遇到了UIWebView的问题.我想在UIWebView中呈现我自己的html代码.

如果我使用下面的代码,它工作正常.

    NSBundle *thisBundle = [NSBundle mainBundle];
    NSString *path = [thisBundle pathForResource:@"foo" ofType:@"html"];
    NSURL *baseURL = [NSURL fileURLWithPath:path];
    [self.webView loadHTMLString:@"foo.html" baseURL:baseURL];
Run Code Online (Sandbox Code Playgroud)

我想用下面的代码渲染html.但它不起作用.foo.html包含与NSString*one完全相同的内容.任何提示?提前致谢.=)

    NSString* one = @"<html><head><title></title></head><body><img src=\"image.jpg\"/></body></html>";
    [self.webView loadHTMLString:one baseURL:nil] ;
Run Code Online (Sandbox Code Playgroud)

Oli*_*ver 23

我使用这个完美的代码:

NSString* htmlContent = @"<html><head><title></title></head><body><img src='image.jpg' /></body></html>";
[self.webView loadHTMLString:htmlContent baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];
Run Code Online (Sandbox Code Playgroud)

确保image.jpg包含在您的项目中.