add selected management

This commit is contained in:
Ran Greenberg 2016-06-30 17:57:34 +03:00
parent 960b34a73a
commit fb571a7442
2 changed files with 11 additions and 7 deletions

View File

@ -117,7 +117,7 @@ static NSString * const CellReuseIdentifier = @"Cell";
allPhotosOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:YES]];
if ([albumName caseInsensitiveCompare:@"all photos"] == NSOrderedSame || !albumName || [albumName isEqualToString:@""]) {
// self.assetsCollection = [PHAsset fetchAssetsWithOptions:allPhotosOptions];
// self.assetsCollection = [PHAsset fetchAssetsWithOptions:allPhotosOptions];
PHFetchResult *allPhotosFetchResults = [PHAsset fetchAssetsWithOptions:allPhotosOptions];
self.galleryData = [[GalleryData alloc] initWithFetchResults:allPhotosFetchResults];
@ -132,7 +132,6 @@ static NSString * const CellReuseIdentifier = @"Cell";
if ([collection.localizedTitle isEqualToString:albumName]) {
// self.assetsCollection = [PHAsset fetchAssetsInAssetCollection:collection options:nil];
PHFetchResult *collectionFetchResults = [PHAsset fetchAssetsInAssetCollection:collection options:nil];
self.galleryData = [[GalleryData alloc] initWithFetchResults:collectionFetchResults];
[self.collectionView reloadData];
@ -156,6 +155,8 @@ static NSString * const CellReuseIdentifier = @"Cell";
PHAsset *asset = assetDictionary[@"asset"];
CKGalleryCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellReuseIdentifier forIndexPath:indexPath];
cell.isSelected = ((NSNumber*)assetDictionary[@"isSelected"]).boolValue;
cell.representedAssetIdentifier = asset.localIdentifier;
[self.imageManager requestImageForAsset:asset
@ -179,9 +180,10 @@ static NSString * const CellReuseIdentifier = @"Cell";
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
id selectedCell =[collectionView cellForItemAtIndexPath:indexPath];
NSDictionary *assetDictionary = (NSDictionary*)self.galleryData.data[indexPath.row];
NSMutableDictionary *assetDictionary = (NSMutableDictionary*)self.galleryData.data[indexPath.row];
PHAsset *asset = assetDictionary[@"asset"];
NSNumber *isSelectedNumber = assetDictionary[@"isSelected"];
assetDictionary[@"isSelected"] = [NSNumber numberWithBool:!(isSelectedNumber.boolValue)];
if ([selectedCell isKindOfClass:[CKGalleryCollectionViewCell class]]) {
CKGalleryCollectionViewCell *ckCell = (CKGalleryCollectionViewCell*)selectedCell;
@ -189,7 +191,6 @@ static NSString * const CellReuseIdentifier = @"Cell";
[self.selectedAssets removeObject:asset];
if (ckCell.isSelected) {
if (asset) {
[self.selectedAssets addObject:asset];

View File

@ -35,8 +35,11 @@
NSMutableArray *array = [[NSMutableArray alloc] init];
for (PHAsset *asset in fetchResults) {
NSDictionary *assetDictionary = @{@"asset": asset,
@"isSelected:": @NO};
NSMutableDictionary *assetDictionary = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
asset, @"asset",
[NSNumber numberWithBool:NO], @"isSelected",
nil];
[array addObject:assetDictionary];
}