-1
 func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
    imagePicker.allowsEditing =  false
    imagePicker.sourceType = .PhotoLibrary
    self.presentViewController(imagePicker, animated: true, completion: nil)



}
 //  func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
   // picker .dismissViewControllerAnimated(true, completion: nil)
 // }
       func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {


    }

on clicking on the cell, im able to open the gallery, i need to save the image pressed and display it in the cell, any help?

Larme
  • 24,190
  • 6
  • 51
  • 81
Ali Jaber
  • 133
  • 1
  • 12

2 Answers2

1

You need to use "AssetsLibrary" framework to get Images from device.

You can find solution on following link - Solution link AssetsLibrary is deprecated in iOS 9.0

So new "Photo" framework used.

Here is swift code using new framework.

func getAllImages() {

    let imgManager     : PHImageManager!        = PHImageManager.defaultManager()
    let photosArray    : NSMutableArray!        = NSMutableArray()
    let requestOptions : PHImageRequestOptions! = PHImageRequestOptions()
    let fetchOptions   : PHFetchOptions!        = PHFetchOptions()

    requestOptions.synchronous = true

    if let fetchResult: PHFetchResult = PHAsset.fetchAssetsWithMediaType(PHAssetMediaType.Image, options: fetchOptions) {

        if fetchResult.count > 0 {

            for i in 0...fetchResult.count {
                imgManager.requestImageForAsset(fetchResult.objectAtIndex(i) as! PHAsset, targetSize: view.frame.size, contentMode: PHImageContentMode.AspectFill, options: requestOptions, resultHandler: { (image, _) in
                    photosArray.addObject(image!)
                });
            }
        }
    }
}

You need to include header using this code - "import Photo"

Community
  • 1
  • 1
Meet
  • 609
  • 6
  • 10
0

var pickedImage = UIImageView()

pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage

in cellForRowAtIndexPath Method Of CollectionView

cell.imageview.image = pickedImage

shelly
  • 9
  • 1