开发者

Images not showing in device for Web view in iphone

开发者 https://www.devze.com 2023-03-04 14:20 出处:网络
I am working on one application. I stuck with one problem. I have HTML page and some images are in Resource Directory. Whenever i run the application on Simulator it works perfectly fine. But when i r

I am working on one application. I stuck with one problem. I have HTML page and some images are in Resource Directory. Whenever i run the application on Simulator it works perfectly fine. But when i run the application on the device the image are not displaying but text is displaying only and instead of image Question mark is showing.

Code: NSString *path = [[NSBundle mainBundle] pathForResourc开发者_Python百科e:@"test1" ofType:@"html"]; NSFileHandle *readHandle = [NSFileHandle fileHandleForReadingAtPath:path];

NSString *htmlString = [[NSString alloc] initWithData: [readHandlereadDataToEndOfFile]encoding:NSUTF8StringEncoding];
 NSURL *baseurl = [NSURL fileURLWithPath:path];
[self.webView loadHTMLString:htmlString baseURL:baseurl];

HTML Code:

  <img src="mainGrid.png">


Change your HTML code to (file:// tells that it's local resource):

<img src='file://%@'>

Then use it in this way:

NSString *pathToLocalImage = [[NSBundle mainBundle] pathForResource:@"mainGrid" ofType:@"jpg"];
NSString *content = [NSString stringWaithFormat:htmlString, pathToLocalImage];
[self.webView content baseURL:nil];
0

精彩评论

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

关注公众号