Iphone 未从引用文件夹(蓝色文件夹)在UIWebview上设置图像

Iphone 未从引用文件夹(蓝色文件夹)在UIWebview上设置图像,iphone,objective-c,Iphone,Objective C,当我试图从引用文件夹加载UIWebView上的图像时,它会显示一个蓝色的小问号,我的代码是: NSString *imagePath=[NSString stringWithFormat:@"dataResources/IMG_0878.jpg"]; [webView loadHTMLString:[NSString stringWithFormat:@"<img src=\"file://%@\"/>",imagePath] baseURL:nil]; 请建议我如何解决此问题可

当我试图从引用文件夹加载UIWebView上的图像时,它会显示一个蓝色的小问号,我的代码是:

NSString *imagePath=[NSString stringWithFormat:@"dataResources/IMG_0878.jpg"];

[webView loadHTMLString:[NSString stringWithFormat:@"<img src=\"file://%@\"/>",imagePath] baseURL:nil];

请建议我如何解决此问题

可能是您的HTML字符串错误。用这个

NSString *path = [[NSBundle mainBundle] pathForResource:@"IMG_0878" ofType:@"jpg"];
[webView loadHTMLString:[NSString stringWithFormat:@"<html><body><img src=\"file://%@\"></body></html>",path] baseURL:nil];
NSString*path=[[NSBundle mainBundle]pathForResource:@“jpg”类型的“IMG_0878”;
[webView loadHTMLString:[NSString stringWithFormat:@',path]baseURL:nil];
NSString*imagePath=[[NSBundle mainBundle]pathForResource:@“jpg”类型的“IMG_0878”;
NSURL*bundleUrl=[[NSBundle mainBundle]bundleUrl];
[webView loadHTMLString:[NSString stringWithFormat:@',imagePath]baseURL:bundleUrl];

您没有设置bundleUrl

HTML字符串为wright,但感谢您的回答,实际上我发现问题在于我们无法在web视图上显示.jpg和.png等图像格式,我们只能使用.gif图像格式,而且如果我们要显示.jpg和.png格式,则必须传递服务器URL/路径,而不是本地资源路径。好,我建议您将其作为答案发布,以便其他人可以参考。
NSString *path = [[NSBundle mainBundle] pathForResource:@"IMG_0878" ofType:@"jpg"];
[webView loadHTMLString:[NSString stringWithFormat:@"<html><body><img src=\"file://%@\"></body></html>",path] baseURL:nil];
NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"IMG_0878" ofType:@"jpg"];    

NSURL *bundleUrl = [[NSBundle mainBundle] bundleURL];

[webView loadHTMLString:[NSString stringWithFormat:@"<img src=\"file://%@\"/>",imagePath] baseURL:bundleUrl];