开发者

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...

- (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. Alternatively, you could pass the path in as the baseURL: argument.


Instead of baseURL:nil, try baseURL:[NSURL URLWithString:[[NSBundle mainBundle] bundlePath]]]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜