Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 1.86 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  2.    
  3.     static NSString *CellIdentifier = @"Cell";
  4.    
  5.     AlbumContentsTableViewCell *cell = (AlbumContentsTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  6.     if (cell == nil) {
  7.         [[NSBundle mainBundle] loadNibNamed:@"AlbumContentsTableViewCell" owner:self options:nil];
  8.         cell = tmpCell;
  9.         tmpCell = nil;
  10.     }
  11.    
  12.     cell.rowNumber = indexPath.row;
  13.     cell.selectionDelegate = self;
  14.    
  15.     // Configure the cell...
  16.     NSUInteger firstPhotoInCell = indexPath.row * 4;
  17.     NSUInteger lastPhotoInCell  = firstPhotoInCell + 4;
  18.    
  19.     if (assets.count <= firstPhotoInCell) {
  20.         NSLog(@"We are out of range, asking to start with photo %d but we only have %d", firstPhotoInCell, assets.count);
  21.         return nil;
  22.     }
  23.    
  24.     NSUInteger currentPhotoIndex = 0;
  25.     NSUInteger lastPhotoIndex = MIN(lastPhotoInCell, assets.count);
  26.     for (firstPhotoInCell ; firstPhotoInCell + currentPhotoIndex < lastPhotoIndex ; currentPhotoIndex++) {
  27.        
  28.         ALAsset *asset = [assets objectAtIndex:firstPhotoInCell + currentPhotoIndex];
  29.                 dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
  30.                 dispatch_async(queue, ^{
  31.                         CGImageRef thumbnailImageRef = [asset thumbnail];
  32.                         UIImage *thumbnail = [UIImage imageWithCGImage:thumbnailImageRef];
  33.                        
  34.                         dispatch_async(dispatch_get_main_queue(), ^ {
  35.                                 switch (currentPhotoIndex) {
  36.                                         case 0:
  37.                                                 [cell photo1].image = thumbnail;
  38.                                                 break;
  39.                                         case 1:
  40.                                                 [cell photo2].image = thumbnail;
  41.                                                 break;
  42.                                         case 2:
  43.                                                 [cell photo3].image = thumbnail;
  44.                                                 break;
  45.                                         case 3:
  46.                                                 [cell photo4].image = thumbnail;
  47.                                                 break;
  48.                                         default:
  49.                                                 break;
  50.                                 }
  51.                         });
  52.                 });
  53.                
  54.         }
  55.        
  56.         return cell;
  57. }