loadHTMLString baseURL:nil在iOS5中不起作用 [英] loadHTMLString baseURL:nil not working in iOS5
本文介绍了loadHTMLString baseURL:nil在iOS5中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到了UIWebView的问题。我想在UIWebView中呈现我自己的html代码。
I got a problem with UIWebView. I want to render my own html code in UIWebView.
如果我使用下面的代码,它工作正常。
if I use the below code, it's working fine.
NSBundle *thisBundle = [NSBundle mainBundle];
NSString *path = [thisBundle pathForResource:@"foo" ofType:@"html"];
NSURL *baseURL = [NSURL fileURLWithPath:path];
[self.webView loadHTMLString:@"foo.html" baseURL:baseURL];
我想用下面的代码渲染html。但它不起作用。 foo.html包含与NSString * one完全相同的内容。任何提示?提前致谢。 =)
I want to render the html with below code. But it's not working. foo.html contains exactly the same content with the NSString* one. Any hints? Thanks in advance. =)
NSString* one = @"<html><head><title></title></head><body><img src=\"image.jpg\"/></body></html>";
[self.webView loadHTMLString:one baseURL:nil] ;
推荐答案
我使用的代码完美无缺:
I use this code that works perfectly :
NSString* htmlContent = @"<html><head><title></title></head><body><img src='image.jpg' /></body></html>";
[self.webView loadHTMLString:htmlContent baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];
确保image.jpg包含在您的项目中。
Bu sure that image.jpg is included into your project.
这篇关于loadHTMLString baseURL:nil在iOS5中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文