我試圖構建一個類似於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