title: lazy loading images in UIScrollView
body: <p>I have an application the requires scrolling of many images.</p>
  
  <p>because I can not load all the images, and save it in the memory, I am lazy loading them.</p>
  
  <p>The problem is if I scroll too quickly, there are "black images" showing (images that did not manage to load).</p>
  
  <p>this is the lazy loading code:
  <code>
          int currentImageToLoad = [self calculateWhichImageShowing] + imageBufferZone;
          [(UIView*)[[theScrollView subviews] objectAtIndex:0]removeFromSuperview];
          PictureObject *pic = (PictureObject *)[imageList objectAtIndex:currentImageToLoad];</p>
  
  <pre><code>    MyImageView *iv = [[MyImageView alloc] initWithFrame:CGRectMake(currentImageToLoad * 320.0f, 20.0f, 320.0f, 460)];
      NSData *imageData = [NSData dataWithContentsOfFile:[pic imageName]];
      [iv setupView:[UIImage imageWithData: imageData] :[pic imageDescription]];
      [theScrollView insertSubview:iv atIndex:5];
      [iv release];
  </code></pre>
  
  <p></code></p>
  
  <p>this is the code inside scrollViewWillBeginDecelerating:</p>
  
  <p><code></p>
  
  <pre><code>[NSThread detachNewThreadSelector:@selector(lazyLoadImages) toTarget:self withObject:nil];
  </code></pre>
  
  <p></code></p>