获取相机胶卷照片到自定义集合视图

我有一个单元格的自定义集合视图。 这是我的CollectionView代码。

- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath; { Cell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"MY_CELL" forIndexPath:indexPath]; return cell; } 

我想要从这些单元中的相机滚动和显示图像。 我怎样才能让相机胶卷图像在这个单元格中查看? 我应该使用数组来存储图像的名称,然后在单元格中显示它们吗? 任何人都可以请给我一个代码的解决scheme。

您可以使用<AssetsLibrary/AssetsLibrary.h>框架获取专辑和照片/video资产:

 -(void)getAlbum { library = [[ALAssetsLibrary alloc] init]; ALAssetsLibraryGroupsEnumerationResultsBlock listGroupBlock = ^(ALAssetsGroup *group, BOOL *stop) { if (group) { [_albumsArray addObject:group]; } else { [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO]; } }; [library enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:listGroupBlock failureBlock:failureBlock] } 

select相册时,您将通过以下方法获取照片/video

 -(void)getAssets { ALAssetsGroupEnumerationResultsBlock assetsEnumerationBlock = ^(ALAsset * result, NSUInteger index, BOOL *stop) { if (result) { } else { [self.tableView reloadData]; } }; [_assetGroup setAssetsFilter:[ALAssetsFilter allAssets]]; [_assetGroup enumerateAssetsUsingBlock:assetsEnumerationBlock]; } 

请参阅此链接了解更多信息和示例与表格视图。 你可以用你的UICollectionViewreplace表视图

谢谢!