loadHTMLString baseURL:nil 在 iOS5 中不起作用 [英] loadHTMLString baseURL:nil not working in iOS5

查看:20
本文介绍了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* 完全相同的内容.有什么提示吗?提前致谢.=)

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆