title: Draw image in UIView using CoreGraphics and draw text on it outside drawRect
body: <p>I have a custom UITableViewCell subclass which shows and image and a text over it.
  The image is downloaded while the text is readily available at the time the table view cell is displayed.</p>
  
  <p>From <a href="https://stackoverflow.com/questions/1352479/tricks-for-improving-iphone-uitableview-scrolling-performance">various places</a>, I read that it is better to just have one view and draw stuff in the view's drawRect method to improve performance as compared to have multiple subviews (in this case a UIImageView view and 2 UILabel views)</p>
  
  <p>I don't want to draw the image in the custom table view cell's <code>drawRect</code> because</p>
  
  <ol>
  <li>the image will probably not be available the first time its called,</li>
  <li>I don't want to draw the whole image everytime someone calls drawRect.</li>
  </ol>
  
  <p>The image in the view should only be done when someone asks for the image to be displayed (example when the network operation completes and image is available to be rendered). The text however is drawn in the -<code>drawRect</code> method.</p>
  
  <p>The problems:</p>
  
  <ol>
  <li><p>I am not able to show the image on the screen once it is downloaded.
  The code I am using currently is-</p>
  
  <pre><code>- (void)drawImageInView
  {
  //.. completion block after downloading from network
    if (image) { // Image downloaded from the network
      UIGraphicsBeginImageContext(rect.size);
      CGContextRef context = UIGraphicsGetCurrentContext();
      CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor);
      CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
      CGContextSetLineWidth(context, 1.0);
      CGContextSetTextDrawingMode(context, kCGTextFill);
  
      CGPoint posOnScreen = self.center;
      CGContextDrawImage(context, CGRectMake(posOnScreen.x - image.size.width/2,
                                         posOnScreen.y - image.size.height/2,
                                         image.size.width,
                                         image.size.height),
                                         image .CGImage);
      UIGraphicsEndImageContext();
    }
  }
  </code></pre></li>
  </ol>
  
  <p>I have also tried:</p>
  
  <pre><code>        UIGraphicsBeginImageContext(rect.size);
          [image drawInRect:rect];
          UIGraphicsEndImageContext();
  </code></pre>
  
  <p>to no avail.</p>
  
  <ol start="2">
  <li>How can I make sure the text is drawn on the on top of the image when it is rendered. Should calling <code>[self setNeedsDisplay]</code> after <code>UIGraphicsEndImageContext();</code> be enough to 
  ensure that the text is rendered on top of the image?</li>
  </ol>