1

我正在调用 infoPage.html,如下所示,其中包含来自 Resources 的图像并在 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];
}
4

2 回答 2

3

您需要使用 [myWebView loadRequest: [NSURLRequest requestWithURL: [NSURL fileURLWithPath: htmlPath]]],而不是 -loadHTML,以便它知道从哪里提取图像。或者,您可以将路径作为 baseURL: 参数传入。

于 2009-11-16T23:54:57.910 回答
1

而不是 baseURL:nil,尝试 baseURL:[NSURL URLWithString:[[NSBundle mainBundle] bundlePath]]]

于 2009-11-17T00:20:51.287 回答