3

I am having a problem with UIWebView. I'd like to render my own html code in it. When I add a webview as a subview and put in some html code it renders just fine. When it gets down to some optimized drawing of tableview cell with the drawRect method the problem pops up. Drawing UIView descendants works pretty well this way. It's even possible to load a URL with the loadRequest method, setting the delegate, conforming to the UIWebViewDelegate protocol and redrawing the table cell with setNeedsDisplay when webViewDidFinishLoad is called. It does show, but when it comes to loadHTMLString, nothing shows up, only a white rect. Due to performance reasons I have to do the drawing in the drawRect method.

Any ideas? Thanks in advance Nick

Example snippet code for the html code being loaded by a UIWebView:

NSString *html = @"<html><head><title>My fancy webview</title></head><body style='background-color:green;'><p>It somehow seems<h2 style='color:black;'>this does not show up in drawRect</h2>!</p></body></html>"; 
[webView loadHTMLString:html baseURL:nil];

Snippet for the drawRect method:

- (void)drawRect:(CGRect)aRect {
    CGContextRef context = UIGraphicsGetCurrentContext();

    [[webView layer] renderInContext:context];
}
Nick Weaver
  • 47,228
  • 12
  • 98
  • 108
  • You could maybe render the web view to the graphics context of an image, keep that image and either add it to your table view cell's view hierarchy or draw it into the graphics context in drawRect depending on your needs. – Heiberg Dec 16 '11 at 19:55

1 Answers1

0

I think you need to relaod the cell at that index rather than calling setNeedsDisplay.

Rajat Talwar
  • 11,922
  • 1
  • 18
  • 12