Skip to content

Commit

Permalink
Fixed setting selected assets
Browse files Browse the repository at this point in the history
  • Loading branch information
davbeck committed Jan 26, 2016
1 parent 8588540 commit e5e9253
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions Pod/Classes/TNKImagePickerController.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,10 @@ - (NSArray *)selectedAssets {
return [_selectedAssets.array copy];
}

- (void)_setSelected:(BOOL)selected forAssets:(NSOrderedSet *)assets {
if (!self.isViewLoaded) {
return;
}

for (TNKAssetCell *cell in self.collectionView.visibleCells) {
if ([assets containsObject:cell.asset]) {
cell.assetSelected = selected;
}
}
}

- (void)addSelectedAssets:(NSOrderedSet *)objects {
[_selectedAssets unionOrderedSet:objects];

[self _setSelected:YES forAssets:objects];
[self _updateSelection];
[self _updateDoneButton];
[self _updateSelectAllButton];
}
Expand All @@ -90,7 +78,7 @@ - (void)selectAsset:(PHAsset *)asset {
- (void)removeSelectedAssets:(NSOrderedSet *)objects {
[_selectedAssets minusOrderedSet:objects];

[self _setSelected:NO forAssets:objects];
[self _updateSelection];
[self _updateDoneButton];
[self _updateSelectAllButton];
}
Expand Down Expand Up @@ -221,13 +209,12 @@ - (void)_updateToolbarItems:(BOOL)animated {
}

- (void)_updateSelection {
for (NSIndexPath *indexPath in self.collectionView.indexPathsForSelectedItems) {
[self.collectionView deselectItemAtIndexPath:indexPath animated:NO];
if (!self.isViewLoaded) {
return;
}

for (PHAsset *asset in _selectedAssets) {
NSIndexPath *indexPath = [self _indexPathForAsset:asset];
[self.collectionView selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
for (TNKAssetCell *cell in self.collectionView.visibleCells) {
cell.assetSelected = [_selectedAssets containsObject:cell.asset];
}
}

Expand Down

0 comments on commit e5e9253

Please sign in to comment.