iphone - 从 iPhone 照片库获取照片并在表格 View 中显示

标签 iphone xcode alassetslibrary

我想在表格 View 中显示照片库中的所有图像。我可以通过 assetLibrary 访问所有图像,但无法在表格中显示它们。我没有收到任何错误,但仍然不知道发生了什么。

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

TableView 的数据源方法:

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

}

请帮助我做错了什么......

感谢帮助

最佳答案

您可以引用以下链接来解决您的问题

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

关于iphone - 从 iPhone 照片库获取照片并在表格 View 中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10174272/

相关文章:

ios - UIDatePicker 结果到 dateByAddingTimeInterval

iphone - "CGBitmapContextCreate: invalid data bytes/row"... 为什么 camera+ 过滤会打乱我的图像裁剪程序?

iphone - 如何更改Application Delegate 类?

ios - UIButton 层样式使应用程序变慢

从照片库快速调整图像(ALAssets)的缩略图

iphone - 从 iPhone 相册导入和保存照片的正确方法是什么?

objective-c - 从 ALAsset URL 创建时,AVAsset 没有轨道或持续时间

iphone - 有谁知道在 IOS 6.0 中不推荐使用哪些方法?

cocoa - 用于获取其他应用程序的窗口/文档名称的 API

swift - 多个命令产生 Assets 问题(xcode11)