
Untitled
By: a guest on
May 8th, 2012 | syntax:
None | size: 1.86 KB | hits: 13 | expires: Never
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
AlbumContentsTableViewCell *cell = (AlbumContentsTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"AlbumContentsTableViewCell" owner:self options:nil];
cell = tmpCell;
tmpCell = nil;
}
cell.rowNumber = indexPath.row;
cell.selectionDelegate = self;
// Configure the cell...
NSUInteger firstPhotoInCell = indexPath.row * 4;
NSUInteger lastPhotoInCell = firstPhotoInCell + 4;
if (assets.count <= firstPhotoInCell) {
NSLog(@"We are out of range, asking to start with photo %d but we only have %d", firstPhotoInCell, assets.count);
return nil;
}
NSUInteger currentPhotoIndex = 0;
NSUInteger lastPhotoIndex = MIN(lastPhotoInCell, assets.count);
for (firstPhotoInCell ; firstPhotoInCell + currentPhotoIndex < lastPhotoIndex ; currentPhotoIndex++) {
ALAsset *asset = [assets objectAtIndex:firstPhotoInCell + currentPhotoIndex];
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
CGImageRef thumbnailImageRef = [asset thumbnail];
UIImage *thumbnail = [UIImage imageWithCGImage:thumbnailImageRef];
dispatch_async(dispatch_get_main_queue(), ^ {
switch (currentPhotoIndex) {
case 0:
[cell photo1].image = thumbnail;
break;
case 1:
[cell photo2].image = thumbnail;
break;
case 2:
[cell photo3].image = thumbnail;
break;
case 3:
[cell photo4].image = thumbnail;
break;
default:
break;
}
});
});
}
return cell;
}