title: How to cache images for a tableview?
body: <p>I have the following code:</p>
  
  <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  //P1
  UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell Identifier"] autorelease];
  cell.textLabel.text = [photoNames objectAtIndex:indexPath.row];
  
  //Check if object for key exists, load from cache, otherwise, load
  
      id cachedObject = [_cache objectForKey:[photoURLs objectAtIndex:indexPath.row]];
  
      if (cachedObject == nil) {
          //IF OBJECT IS NIL, SET IT TO PLACEHOLDERS
          cell.imageView.image = cachedObject;
          [self setImage:[UIImage imageNamed:@"loading.png"] forKey:[photoURLs objectAtIndex:indexPath.row]];
          [cell setNeedsLayout];
  
      } else {
          //fetch imageData
          dispatch_async(kfetchQueue, ^{
              //P1
              NSData *imageData = [NSData dataWithContentsOfURL:[photoURLs objectAtIndex:indexPath.row]];
                  dispatch_async(dispatch_get_main_queue(), ^{
                      cell.imageView.image = [UIImage imageWithData:imageData];
                      [self setImage:cell.imageView.image forKey:cell.textLabel.text];
                      [cell setNeedsLayout];
                  });
          });
      }
  return cell;
  </code></pre>
  
  <p>}</p>
  
  <p>Other than this, the viewDidLoad method fetches from the web, the json result from flickr, to populate a photoNames and photoURLs.  Im trying to cache already downloaded images into a local NSDictionary.  The problem is that the images arent loaded.  Not even the loading.png placeholder image.</p>