[英]Image not displaying from local html on iPhone webview
I am calling an infoPage.html as below with an image from Resources and referenced as img src="eye.png" in the html, the text displays correctly but I cannot load the image (only a ? appears), any suggestions... 我在下面用一个来自参考资料的图像调用一个infoPage.html,并在html中引用为img src =“eye.png”,文本正确显示但我无法加载图像(只显示?),任何建议.. 。
- (void)viewDidLoad {
[super viewDidLoad];
CGRect webRect = CGRectMake(15,40,300,450);
UIWebView *myWebView = [[UIWebView alloc] initWithFrame:webRect];
myWebView.delegate = self;
myWebView.scalesPageToFit = NO;
NSString *htmlPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"infoPage.html"];
NSString *htmlContent = [NSString stringWithContentsOfFile:htmlPath];
[myWebView loadHTMLString:htmlContent baseURL:nil];
//stop webview from scrolling
[[[myWebView subviews] lastObject] setScrollingEnabled:NO];
[myWebView loadHTMLString:htmlContent baseURL:nil];
[self.view addSubview:myWebView];
[myWebView release];
}
You need to use [myWebView loadRequest: [NSURLRequest requestWithURL: [NSURL fileURLWithPath: htmlPath]]], rather than -loadHTML so that it knows where to extract images from. 您需要使用[myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:htmlPath]]]而不是-loadHTML,以便它知道从哪里提取图像。 Alternatively, you could pass the path in as the baseURL: argument. 或者,您可以将路径作为baseURL:参数传递。
而不是baseURL:nil,尝试baseURL:[NSURL URLWithString:[[NSBundle mainBundle] bundlePath]]]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.