Skip to content

Commit

Permalink
use pickedImages to hold selected images' order in PickPhotos
Browse files Browse the repository at this point in the history
  • Loading branch information
nixzhu committed Jan 22, 2016
1 parent 55ad1c7 commit b2cf340
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class PickPhotosViewController: UICollectionViewController, PHPhotoLibraryChange
var imageCacheController: ImageCacheController!

var pickedImageSet = Set<PHAsset>()
var pickedImages = [PHAsset]()
var completion: ((images: [UIImage], imageAssets: [PHAsset]) -> Void)?
var imageLimit = 0

Expand Down Expand Up @@ -64,7 +65,7 @@ class PickPhotosViewController: UICollectionViewController, PHPhotoLibraryChange

let options = PHImageRequestOptions.yep_sharedOptions

let pickedImageAssets = Array(pickedImageSet)
let pickedImageAssets = pickedImages

for imageAsset in pickedImageAssets {

Expand Down Expand Up @@ -137,11 +138,15 @@ class PickPhotosViewController: UICollectionViewController, PHPhotoLibraryChange
if let imageAsset = images[indexPath.item] as? PHAsset {
if pickedImageSet.contains(imageAsset) {
pickedImageSet.remove(imageAsset)
if let index = pickedImages.indexOf(imageAsset) {
pickedImages.removeAtIndex(index)
}
} else {
if pickedImageSet.count + imageLimit == 4 {
return
}
pickedImageSet.insert(imageAsset)
pickedImages.append(imageAsset)
}
title = "\(NSLocalizedString("Pick Photos", comment: "")) (\(pickedImageSet.count + imageLimit)/4)"
let cell = collectionView.cellForItemAtIndexPath(indexPath) as! PhotoCell
Expand Down

0 comments on commit b2cf340

Please sign in to comment.