title: Load UIImage from file using grand central dispatch
body: <p>I'm trying to load images in the background using gcd. My first attempt didn't work:</p>
  
  <pre><code>dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW,0), ^{
    dispatch_async(dispatch_get_main_queue(), ^{
      // create UI Image, add to subview
    });
  });
  </code></pre>
  
  <p>commenting out the background queue code and leaving just the main queue dispatch block didn't work:</p>
  
  <pre><code>dispatch_async(dispatch_get_main_queue(), ^{
    // create UI Image, add to subview
  });
  </code></pre>
  
  <p>Is there some trick to doing ui stuff inside a gcd block?</p>
  
  <p>In response to  mattjgalloway's comment, I'm simply trying to load a big image in a background thread. Here's the full code that I tried originally:</p>
  
  <pre><code>dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW,0), ^{
  
      UIImage* img = [[UIImage alloc] initWithContentsOfFile: path];
  
      dispatch_async(dispatch_get_main_queue(), ^{
  
         imageView = [[[UIImageView alloc] initWithImage:  img] autorelease];
         imageView.contentMode = UIViewContentModeScaleAspectFill;
         CGRect photoFrame = self.frame;
         imageView.frame = photoFrame;
         [self addSubview:imageView];
  
    });
  
  });
  </code></pre>
  
  <p>I simplified it so that I was running everything inside the main queue, but even then it didn't work. I figure if I can't get the whole thing to work in the main queue, no way the background queue stuff will work.</p>
  
  <hr>
  
  <p>================ UPDATE ==============</p>
  
  <p>I tried the above technique (gcd and all) in a brand new project and it does indeed work as expected. Just not in my current project. So I'll have to do some slow, painful process of elimination work to figure out what's going wrong. I'm using this background loading to display images in a uiscrollview. Turns out bits of the images do sometimes show up, but not always. I'll get to the bottom of this....</p>
  
  <p>================ UPDATE ==============</p>
  
  <p>Looks like the issue is related to the UIScrollView all of this is inside. I think stuff isn't getting drawn/refreshed when it should</p>