我试图构建一个类似于iOS
7的照片应用的自定义图像选择器。我能够从相机胶卷中挑选一张照片(ALAssetsGroupSavedPhotos
),但我很难从另一张相册中加载单张图像 - 我为测试目的而创建的一张相册。ALAssetsLibrary从ALAssetsGroupAll加载单张照片
下面是我使用的加载从相机胶卷照片的代码:
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
[group setAssetsFilter:[ALAssetsFilter allPhotos]];
numberOfPhotos = [group numberOfAssets];
[group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:index] options:0 usingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop) {
if (alAsset) {
ALAssetRepresentation *representation = [alAsset defaultRepresentation];
UIImage *lastImage = [UIImage imageWithCGImage:[representation fullScreenImage]];
}
}];
}
failureBlock: ^(NSError *error2) {
}];
我试图取代ALAssetsGroupSavedPhotos
与ALAssetsGroupAll
但它返回以下错误:
Terminating app due to uncaught exception 'NSRangeException', reason: 'indexSet count or lastIndex must not exceed -numberOfAssets'
你如何定义'index'? – RaffAl
reecon索引是我试图根据表格视图单元格中的缩略图位置选择的照片的编号。谢谢。 – user1752054