title: UIWebView loading parsed html string
body: <p>i'm building an app that will display some newsletters to the users. the newsletters are displayed in a uiWebView. I'm reading the url's for the newsletters from an rss feed. I parse the xml, and in a table view i have all the newsletters. When a cell is clicked the uiWebView is pushed and the newsletter is loaded. Because the uiWebView doesn't open links that have target=_blank i need to replace the _blank from target with "". In an NSOperation i download the contents of the html and after the download is finished i replace the strings like this:</p>
  
  <pre><code>NSMutableString *page = [[[NSMutableString alloc] initWithData:pageData encoding:NSISOLatin1StringEncoding] autorelease]; [page replaceOccurrencesOfString:@"target=_blank" withString:@"target=""" options:0 range:NSMakeRange(0, [page length])];
  </code></pre>
  
  <p>after i do this i load the parsed string in the webView to display it to the user.</p>
  
  <pre><code>[myWebView loadHTMLString:page baseURL:[NSURL URLWithString:@""]];
  </code></pre>
  
  <p>while the NSOperation is downloading the contents of the page an HUD with a activity indicator and a label that says Loading is showed. When the download is finished the HUD is removed from the superview.</p>
  
  <p>so far so good..but here come the questions. i used the NSOperation with the callback function because i wasn't able to determine the last call to webDidFinishLoading (  i read this <a href="https://stackoverflow.com/questions/908367/uiwebview-how-to-identify-the-last-webviewdidfinishload-message">UIWebView - How to identify the &quot;last&quot; webViewDidFinishLoad message?</a> - this is a part of my problem but the response was to use some Apple private classes and that is a problem for me). so i'm doing this:</p>
  
  <pre><code>- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
  
  
  NSURL *url = request.URL;
  NSString *urlString = url.absoluteString;
  NSLog(@"WebViewSouldStartWithRequest: %@", urlString);
  if (navigationType == UIWebViewNavigationTypeLinkClicked)
  {
      if(![urlString isEqualToString:@"about:blank"])
      {
          NSLog(@"FeedViewController: startPageLoad");
          activityHud = [[HUDView alloc] initWithFrame:CGRectMake(110, 100, 80, 80)];
          [activityHud setText:@"Loading"];
          [myWebView addSubview:activityHud];
          NSLog(@"FeedViewController: pageUrl = %@", urlString);
          [self resetWebView];
          [urlLoader loadPageFromUrl:request.URL withCallbackTarget:self withCallbackSelector:@selector(endLoading:)];
      }
  }
  
  return NO;
  </code></pre>
  
  <p>}</p>
  
  <pre><code>- (void) endLoading:(NSMutableString *)page { [self resetWebView]; NSLog(@"FeedViewController: endLoading"); [activityHud removeFromSuperview]; [myWebView loadHTMLString:page baseURL:[NSURL URLWithString:@""]]; }
  </code></pre>
  
  <p>after i touch a cell in the table view and the newsletter is showed it looks like it should, when i click a link in the newsletter, the page is loaded with the new request, parsed but visually is not looking as it should (i looked at the page after parsing in NSLog and it has the css styles and html tags, head, body opened and closed correctly) anyone had this problem with uiWebView, not showing webpages correctly?</p>
  
  <p>i tried loading the page with <code>- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType{ return YES; }</code>
  and in - (void)webViewDidFinishLoad:(UIWebView *)webview  {} and in - webViewDiStartLoad</p>
  
  <p>but the methods are being called for every item that is loaded in the webview so showing and hiding the HUD in those method is not a good solution.</p>
  
  <p>I encountered some problems while using - (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType { ... return NO }</p>
  
  <p>for example links that have paths like this /bilder-galerien to not work and in NSLog i receive this for them  </p>
  
  <blockquote>
    <p>Unknown scheme, doing nothing:
    /bilder-galerien</p>
  </blockquote>
  
  <p>but when i use</p>
  
  <ul>
  <li>(BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType { return Yes } and didstartLoading and finishLoading the urls are loaded and i don't know why...</li>
  </ul>
  
  <p>another problem are the special german characters..in my first load(after pressing a cell in the uiTableView) the page is parsed like it should be by the uiWebView but after i click a link and the corresponding request is loaded also the characters are not parsed correctly..</p>
  
  <p>can anyone point me in the good direction? thank you in advance</p>