图像没有显示在设备上的Web视图在iphone

问题描述:

我正在一个应用程序。我坚持一个问题。我有HTML页面,一些图像在资源目录中。每当我在模拟器上运行应用程序,它都可以很好地工作。但是,当我在设备上运行应用程序的图像不显示,但文本只显示,而不是图像问号显示。图像没有显示在设备上的Web视图在iphone

代码: 的NSString *路径= [[一个NSBundle mainBundle] pathForResource:@ “测试1” ofType:@ “HTML”]; NSFileHandle * readHandle = [NSFileHandle fileHandleForReadingAtPath:path];

NSString *htmlString = [[NSString alloc] initWithData: [readHandlereadDataToEndOfFile]encoding:NSUTF8StringEncoding]; 
NSURL *baseurl = [NSURL fileURLWithPath:path]; 
[self.webView loadHTMLString:htmlString baseURL:baseurl]; 

HTML代码:

<img src="mainGrid.png"> 

HTML更改代码(文件://告诉它的本地资源):

<img src='file://%@'> 

然后在此使用方式:

NSString *pathToLocalImage = [[NSBundle mainBundle] pathForResource:@"mainGrid" ofType:@"jpg"]; 
NSString *content = [NSString stringWaithFormat:htmlString, pathToLocalImage]; 
[self.webView content baseURL:nil]; 
+0

它表现出同样的问题亲爱的.. – 2011-05-06 09:28:16

+0

我查过了 - 它适用于我。尝试从设备中删除应用程序,清除项目,检查该图像是否添加到项目资源中,重新构建并重新安装。 – 5hrp 2011-05-06 09:34:31