从iphone照片库中获取照片并在表格视图中显示

前端之家收集整理的这篇文章主要介绍了从iphone照片库中获取照片并在表格视图中显示前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在表格视图中显示照片库中的所有图像.我可以通过assetsLibrary访问所有图像,但无法在表格中显示它们.我没有得到任何错误,但仍然不知道发生了什么.

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");}];

表视图的数据源方法

- (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;

}

请求帮助我做错了….

感谢帮助

解决方法

猜你在找的Xcode相关文章