title: Problem between context and thread in drawRect
body: <p>I'm trying to draw a couple of <code>UIImage</code>s in a <code>UIView</code>, and I'm doing it by hand with <code>drawRect:</code>. Given that the images are dynamically downloaded from the web, I create an <code>NSOperation</code> and I perform the image loading code from a second thread, in order to keep UI responsive. So once the images are downloaded, they appear on screen.</p>
  
  <p>But... I get the following errors, for each of the images:</p>
  
  <pre><code>&lt;Error&gt;: CGContextSaveGState: invalid context 0x0
  &lt;Error&gt;: CGContextSetBlendMode: invalid context 0x0
  &lt;Error&gt;: CGContextSetAlpha: invalid context 0x0
  &lt;Error&gt;: CGContextTranslateCTM: invalid context 0x0
  &lt;Error&gt;: CGContextScaleCTM: invalid context 0x0
  &lt;Error&gt;: CGContextDrawImage: invalid context 0x0
  &lt;Error&gt;: CGContextRestoreGState: invalid context 0x0
  </code></pre>
  
  <p>For what I've seen, this means that the context in which I'm trying to make <code>[image drawInRect...]</code> is <code>nil</code>, because I'm not in <code>drawRect:</code> anymore. </p>
  
  <p>Attempted doing</p>
  
  <pre><code>UIGraphicsPushContext(UIGraphicsGetCurrentContext());
  </code></pre>
  
  <p>before drawing the image but nothing changed. How can I overcome this thing? Multithreading is a must for responsiveness, and the context gets lost in the way.</p>
  
  <p>UPDATE: Here's my code:</p>
  
  <pre><code>- (void)drawContentView:(CGRect)r
  {
      CGContextRef context = UIGraphicsGetCurrentContext();
      ....
      CGContextFillRect(context, r);
      UIApplication* app = [UIApplication sharedApplication];
          app.networkActivityIndicatorVisible = YES;
  
  
      NSOperationQueue *queue = [NSOperationQueue new];
      NSInvocationOperation *operation = [[NSInvocationOperation alloc]
                                              initWithTarget:self 
                                              selector:@selector(loadPreview) 
                                              object:nil];
      [queue addOperation:operation];
      [operation release];
  }
  </code></pre>
  
  <p>And then</p>
  
  <pre><code>-(void)loadPreview
  {
      self.preview = [UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString:self.picStringPreview]]];
      [self.preview drawInRect:CGRectMake(256, 18, 80, 65)];
  }
  </code></pre>
  
  <p>I tried adding a <code>UIGraphicsPushContext...</code> in <code>loadPreview</code>, even doing a <code>[self performSelectorOnMainThread...]</code> there, and nothing. And this is a custom cell based on Atebit's model, so my cell's superclass makes:</p>
  
  <pre><code>- (void)drawRect:(CGRect)r
  {
      [(ABTableViewCell *)[self superview] drawContentView:r];
  }
  </code></pre>
  
  <p>and the code in <code>drawContentView:</code> gets draw'd in superclass's <code>drawRect:</code>. Any hint?</p>