title: Lazy load images for UITableViewCells from NSDocumentDirectory?
body: <p>I have a <code>UITableView</code> in my app in which I load several images from the <code>NSDocumentDirectory</code>. It <em>works</em>, but when scrolling up and down, the app seems to freeze a bit, most likely because of the images being served in the main thread, effectively blocking the tableView from scrolling until it's loaded. My problem is that I don't know how to load them in later, a "lazy load" feature, while scrolling.</p>
  
  <p>This is the code snippet used to load the images now:</p>
  
  <pre><code>imagesPath = [NSString stringWithFormat:@"%@/images/", [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]];
  if ([fileManager fileExistsAtPath:[imagesPath stringByAppendingPathComponent:[NSString stringWithFormat:@"/%d.png", rowID]]]) {
      UIImage *image = [[UIImage alloc] initWithContentsOfFile:[imagesPath stringByAppendingPathComponent:[NSString stringWithFormat:@"/%d.png", rowID]]];
      // If image contains anything, set cellImage to image. If image is empty, use default, noimage.png.
      if (image != nil){
          // If image != nil, set cellImage to that image
          cell.cellImage.image = image;
      }
      [image release];
  }
  </code></pre>
  
  <p>What is the best way to "lazy load" the images in each cell to avoid lagging in the scrolling?</p>