views:

831

answers:

2

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]; }

+2  A: 

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.

Ben Gottlieb
+1  A: 

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

Kendall Helmstetter Gelner
credit to JTBandes who posted this originally as a comment to the main question, but it needed to be an answer. I made this a community WIKI so I get no points for upvotes or having it marked correctly, and will delete if JTBandes comes back to post his answer as an answer.
Kendall Helmstetter Gelner
You need a URL, not a string for the baseURL
Casebash