ios - 仅自定义相册的 PHFetchResult

标签 ios uicollectionview phfetchoptions

我只是想将位于名为“MyFolder”的自定义文件夹中的照片访问到我的 UICollectionView。我可以使用以下代码轻松地处理“所有照片和视频”,但我不知道如何过滤结果以仅包含我的文件夹名称:

PHFetchOptions *allPhotosOptions = [PHFetchOptions new];
allPhotosOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:YES]];

PHFetchResult *videos = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeVideo options:allPhotosOptions];

[videos enumerateObjectsUsingBlock:^(PHAsset *asset, NSUInteger idx, BOOL *stop) {
      //add assets to array
}];

我试过用这个:

allPhotosOptions.predicate = [NSPredicate predicateWithFormat:@"title = %@", @"Coached"];

但它不起作用。有人可以帮我吗?

最佳答案

哇。经过大约 5 个多小时的痛苦。这很简单。这是有效的代码:

__block PHAssetCollection *collection;

// Find the album
PHFetchOptions *fetchOptions = [[PHFetchOptions alloc] init];
fetchOptions.predicate = [NSPredicate predicateWithFormat:@"title = %@", @"YOUR_CUSTOM_ALBUM_NAME"];
collection = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum
                                                      subtype:PHAssetCollectionSubtypeAny
                                                      options:fetchOptions].firstObject;

PHFetchResult *collectionResult = [PHAsset fetchAssetsInAssetCollection:collection options:nil];

[collectionResult enumerateObjectsUsingBlock:^(PHAsset *asset, NSUInteger idx, BOOL *stop) {


        //add assets to an array for later use in the uicollectionviewcell

    }];

关于ios - 仅自定义相册的 PHFetchResult,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33194329/

相关文章:

ios - 在 UISegmentedController 中隐藏一个段

ios - 快速重新安装应用程序后 iCloud 文件不可见

ios - 突出显示或放大选定的单元格?

ios - swift fetchAssetsInAssetCollection : Loading Photos From Range in Camera Roll

ios - 将 PHAsset 获取结果限制为仅 3 个 Assets

objective-c - PHFetchOptions 持续时间无法正常工作

ios - 如何使用 Coreplot 在 CPTLayerHostingView 中添加关闭按钮

ios - 如何在 Storyboard中为 iPad 横向和纵​​向模式将不同的框架设置为相同的 View ?

iphone - 单元格获取其前一个单元格的索引 - Tableview 中的 Collectionview

ios - CollectionView 未显示任何项目