title: Stop asynchronous UITableViewCell image loading when cell is not visible?
body: <p>I'm developing an iOS 5.0+ application with latest SDK.</p>
  
  <p>This is the code I use to load images asynchronously for <code>UITableViewCell</code>.</p>
  
  <pre><code>- (UITableViewCell*)tableView:(UITableView *)tableView
          cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      if ((groups != nil) &amp;&amp; (groups.count &gt; 0))
      {
          GroupCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
          if (cell == nil)
          {
              cell = [[GroupCell alloc] initWithStyle:UITableViewCellStyleDefault
                                       reuseIdentifier:CellIdentifier];
          }
          // Configure the cell...
          Group* group = [groups objectAtIndex:indexPath.row];
  
          cell.GroupNameLabel.text = group.Name;
          // TODO: Poner el estado.
          if (group.Photo)
              cell.GroupImageView.image = group.Photo;
          else
          {
              // download the photo asynchronously
              NSString *urlString =
                  [NSString stringWithFormat:kGetGroupImageURL, [group.GroupId intValue]];
              NSURL *url = [NSURL URLWithString:urlString];
  
              [ImageTool downloadImageWithURL:url completionBlock:^(BOOL succeeded, UIImage *image) {
                  if (succeeded)
                  {
                      // change the image in the cell
                      cell.GroupImageView.image = image;
  
                      // cache the image for use later (when scrolling up)
                      group.Photo = image;
                  }
              }];
          }
  
          return cell;
      }
      else
          return nil;
  }
  </code></pre>
  
  <p>And the loader:</p>
  
  <pre><code>#import "ImageTool.h"
  
  @implementation ImageTool
  
  + (void)downloadImageWithURL:(NSURL *)url
               completionBlock:(void (^)(BOOL succeeded, UIImage *image))completionBlock
  {
      NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
      [NSURLConnection sendAsynchronousRequest:request
                                         queue:[NSOperationQueue mainQueue]
                             completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
                                 if ( !error )
                                 {
                                     UIImage *image = [[UIImage alloc] initWithData:data];
                                     completionBlock(YES,image);
                                 } else{
                                     completionBlock(NO,nil);
                                 }
                             }];
  }
  </code></pre>
  
  <p>But it seems it's not going to work because I don't handle if the cell for which I'm loading the image it is still visible.</p>
  
  <p><strong>How can I handle if the cell is still visible?</strong></p>
  
  <p>I have found this <a href="http://blog.oleganza.com/post/207635553/the-efficient-way-to-load-and-render-images-in-the" rel="nofollow">article</a>, but I don't know how to implement it.</p>