Search code examples
iphonexcodealassetslibrary

get photo from iphone photo library and show in table view


I want to show all the images from the photo library in a table view. I am able to access all the images via assetsLibrary but unable to show them in table. I am not getting any kind of error but still don't know what is going on.

NSMutableArray *assets = [[NSMutableArray alloc]init];

ALAssetsLibrary *library = [[ALAssetsLibrary alloc]init];

[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup   *group,  BOOL *stop){

         if(group != NULL){

        [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop){

                if(result != NULL){
                [assets addObject:result];
                }else NSLog(@"NO photo");;
          }];
     }
}


failureBlock:^(NSError *error){NSLog(@"Error");}];

Datasource method for table view:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

NSString *identifier = @"id";

UITableViewCell *cell = (UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:identifier];  

if(cell == NULL){

    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
}

[cell.imageView setImage:[UIImage imageWithCGImage:[[assets objectAtIndex:indexPath.row]thumbnail]]];

[cell textLabel].text = @"Photo";

return cell;

}

Pleaes help what i am doing wrong....

thanks for help


Solution

  • You can refer following link to solve your Issues

    http://agilewarrior.wordpress.com/tag/alassetslibrary/