views:

266

answers:

2

Hi guys,

Here I am getting a problem when I am loading local Image in the webview using html code my image was not diplaying in my webview here is my code for Loading the local image in webview:

  htmlString = [htmlString stringByAppendingString:@"<table width=85% cellpadding=3  cellspacing=0 border=0> "];
  htmlString = [htmlString stringByAppendingString:@"<tr>"];
  htmlString = [htmlString stringByAppendingString:@"<td >"];
  htmlString = [htmlString stringByAppendingString:@"<div align='Right'><a href='/reviews/"];

  htmlString = [htmlString stringByAppendingString:@"'>"];
  htmlString = [htmlString stringByAppendingString:@"<img src ='reviews1.jpg' BORDER=0 HEIGHT=148 WIDTH=110/>"];



  htmlString = [htmlString stringByAppendingString:@"</a>"];


    - (BOOL)webView:(UIWebView*)webView2 shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {

 //CAPTURE USER LINK-CLICK.
 if (navigationType == UIWebViewNavigationTypeLinkClicked) {
  NSURL *aURL = [request URL];
  NSString* aurlString = [aURL absoluteString];

   if ( [aurlString rangeOfString:@"/reviews/"].location != NSNotFound)
  {
   [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
   ReviewWebViewController*  viewController  = [[ReviewWebViewController alloc] init];

   viewController.loadUrl=[techProducts techProductReviewUrl];
   [self.navigationController pushViewController:viewController animated:YES];
   [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

   [viewController release];

   return NO;
  }
    }
    }

Here no image was displaying only ?mark is displaying .

guys pls help me to get out of dis prb.

Thank you, Monish.

A: 

You may need to supply the full path to the image.

Marcelo Cantos
A: 

This is a duplicate question. For the sake of completeness, I'll link to the answer and repeat it here too:

I found this tutorial a while back. I ended up just using a <style> tag in the end though.

NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
[webView loadHTMLString:htmlString baseURL:baseURL];

Another way of doing this is like so:

-(NSString *)urlForFileNamed:(NSString *) name ofType:(NSString *) type {
  NSString *filePath = [[NSBundle mainBundle] pathForResource: name ofType: type];
  if (!filePath) { NSLog(@"No path found for file %@.%@", name, type); }
  return filePath;
}

-(void)viewDidLoad {
  [super viewDidLoad];

  NSString *path = [[NSBundle mainBundle] bundlePath];
  baseUrl = [NSURL fileURLWithPath: path];

  [view loadHTMLString: [self html] baseURL: [NSURL fileURLWithPath: path]];
}

-(void)html {
  // Obviously the below's just a stub for proper HTML
  return [NSString stringWithFormat: @"<img src=\"@\" />", [self urlForFileNamed: @"foo" ofType: @"png"]];
}
Frank Shearar
htmlString = [htmlString stringByAppendingString:@"<table width=85% cellpadding=3 cellspacing=0 border=0> "]; htmlString = [htmlString stringByAppendingString:@"<br><br><tr>"]; htmlString = [htmlString stringByAppendingString:@"<td>"];
monish
NSString *path = [[NSBundle mainBundle] bundlePath]; NSURL *baseURL = [NSURL fileURLWithPath:path]; //NSString *str = [baseURL absoluteString]; htmlString = [htmlString stringByAppendingString:@"<img src ='"]; htmlString = [htmlString stringByAppendingString:@"reviews.png"]; htmlString = [htmlString stringByAppendingString:@"'/>"]; //htmlString = [htmlString stringByAppendingString:@"'/>"]; printf("\n STR VALUE=====%s",[htmlString UTF8String]); [webView loadHTMLString:htmlString baseURL:baseURL];eventhough Im not displaying my image in the webview.does I made anything wrong
monish