加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 17:37:19 所属栏目:百科 来源:网络整理
导读:我想在表格视图中显示照片库中的所有图像.我可以通过assetsLibrary访问所有图像,但无法在表格中显示它们.我没有得到任何错误,但仍然不知道发生了什么. NSMutableArray *assets = [[NSMutableArray alloc]init];ALAssetsLibrary *library = [[ALAssetsLibrary
我想在表格视图中显示照片库中的所有图像.我可以通过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;

}

请求帮助我做错了….

感谢帮助

解决方法

您可以参考以下链接来解决您的问题

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读