title: RootViewController - tableView:cellForRowAtIndexPath - Load image from assetsLibrary
body: <p>StackOverflow friends and colleague programmers,</p>
  
  <p>My RootViewController (a flowerTableView on a view) should display cell's with title, subtitle and an image thumbnail (loaded from the camera roll).  A very basic table I guess.</p>
  
  <p>All content is stored in 'Core Data' but the images are stored as imagePaths to the camera roll. Example: <code>flower.imagePath = assets-library://asset/asset.JPG?id=1000000002&amp;ext</code></p>
  
  <p>Using the code at the bottom everything should run smoothly but it doesn't . When starting the App the title's and subtitle's are shown, but the images are not. When I press a cell, which display's the detail view, and pop back again to the main view the image for this specific cell is shown.</p>
  
  <p>When I press 'Show All', a button on a toolbar which executes the following code</p>
  
  <pre><code>NSFetchRequest *fetchRequest = [[self fetchedResultsController] fetchRequest];
  [fetchRequest setPredicate:nil];
  
  NSError *error = nil;
  if (![[self fetchedResultsController] performFetch:&amp;error]) {
      NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
      abort();
  }
  [self.flowerTableView reloadData];
  </code></pre>
  
  <p>and reloads the table, all the beautiful flowers are now shown.</p>
  
  <p>Why didn't the flowers be displayed the first time? Is this a caching problem?</p>
  
  <p>When debugging this code the string: 'This debug string was logged after this function was done' was logged after loading the table on starting the app, not after pressing 'Show All'
  This means that all images are loaded from the camera roll successfully but attached to the cell after the cell was displayed and therefore not shown.</p>
  
  <p>The same line is printed as intended when pressing 'Show All'</p>
  
  <p>Hope someone can tell me what's going on here and even better, what to change in my code to make this work. I'm stuck at the moment...</p>
  
  <p>Thank for helping me out!
  Edwin</p>
  
  <p>:::THE CODE:::</p>
  
  <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath (NSIndexPath *)indexPath
  {
  
      Flower *flower = [fetchedResultsController_ objectAtIndexPath:indexPath];
  
      static NSString *CellIdentifier = @"Cell";
  
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
      if (cell == nil) {
          cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
      }
  
      // Configure the cell...
  
      // Display the image if one is defined
      if (flower.imagePath &amp;&amp; ![flower.imagePath isEqualToString:@""])
      {
          // Should hold image after executing the resultBlock
         __block UIImage *image = nil;
  
          ALAssetsLibraryAssetForURLResultBlock resultBlock = ^(ALAsset *asset)
          {
              NSLog(@"This debug string was logged after this function was done");
              image = [[UIImage imageWithCGImage:[asset thumbnail]] retain];
          };
  
          ALAssetsLibraryAccessFailureBlock failureBlock  = ^(NSError *error)
          {
              NSLog(@"Unresolved error: %@, %@", error, [error localizedDescription]);
          };
  
          [assetsLibrary_ assetForURL:[NSURL URLWithString:flower.imagePath] 
                          resultBlock:resultBlock
                         failureBlock:failureBlock];
  
          [cell.imageView setImage:image];
      }
  
      return cell;
  }
  </code></pre>