如何查看带有 NohanaImagePicker pod 文件的图像?

how can I see images with NohanaImagePicker pod file?

我正在使用 swift 3 并使用 NohanaImagePickerpod 文件来 select 多个图像并且它工作正常问题是我想在集合视图中看到 selected 图像并且我将在此行收到致命错误

        cell.imageforCV.image =  ViewController.imgArray[indexPath.row]

我为 imgArray 使用了静态变量

这是我的代码

import UIKit
import Photos
import NohanaImagePicker

class ViewController: UIViewController , NohanaImagePickerControllerDelegate , UICollectionViewDelegate , UICollectionViewDataSource {

static var imgArray = [UIImage]()
static var imgCount = Int()
@IBOutlet weak var imageCollectionView: UICollectionView!
var images = [ PHAsset]()
@IBAction func gallery(_ sender: UIButton) {

 let picker = NohanaImagePickerController()
    picker.delegate = self
    present(picker, animated: true, completion: nil)
    picker.maximumNumberOfSelection  = 200
    print("\(picker)")


}
 func nohanaImagePickerDidCancel(_ picker: NohanaImagePickerController) {
    print("Canceled")
    picker.dismiss(animated: true, completion: nil)
}

   func nohanaImagePicker(_ picker: NohanaImagePickerController, didFinishPickingPhotoKitAssets pickedAssts :[PHAsset]) {
    print("Completed\n\tpickedAssets = \(pickedAssts)")
    picker.dismiss(animated: true, completion: nil)
    performSegue(withIdentifier: "back", sender: self)
    let numberOfImages = pickedAssts.count
    print("\(numberOfImages)")


    ViewController.imgCount = pickedAssts.count

    var phAssetArray : [PHAsset] = []

    for i in 0..<pickedAssts.count
    {
        ViewController.imgArray.append(self.getAssetThumbnail(asset: pickedAssts[i]));
    }
    let size = CGSize(width: 50, height: 50)
    let options = PHImageRequestOptions()

    let manager : PHCachingImageManager =  PHCachingImageManager()


    manager.startCachingImages(for: phAssetArray,
                                                  targetSize: size,
                                                  contentMode: .aspectFill,
                                                  options: options)

    imageCollectionView.reloadData()
              }


func getAssetThumbnail(asset: PHAsset) -> UIImage {
    var retimage = UIImage()
    print(retimage)
    let manager = PHImageManager.default()
    manager.requestImage(for: asset, targetSize: CGSize(width: 50.0, height: 50.0), contentMode: .aspectFit, options: nil, resultHandler: {(result, info)->Void in
        retimage = result!
    })
    print(retimage)
    return retimage
}

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return ViewController.imgArray.count
}


func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "imageCell", for: indexPath) as! imageCell

    print(ViewController.imgArray.count)
    print(indexPath.row)
    print(ViewController.imgArray[indexPath.row])



    cell.imageforCV.image =  ViewController.imgArray[indexPath.row]

    return cell

}


   override func viewDidLoad() {
         super.viewDidLoad()

         imageCollectionView.reloadData()

         self.imageCollectionView!.dataSource = self
         self.imageCollectionView!.delegate = self


    let picker = NohanaImagePickerController()

    // Set the maximum number of selectable images

    // Set the cell size
    picker.numberOfColumnsInPortrait = 2
    picker.numberOfColumnsInLandscape = 3

    // Show Moment
    picker.shouldShowMoment = true

    // Show empty albums
    //        picker.shouldShowMoment = shouldShowEmptyAlbum = true

    // Hide toolbar
    picker.shouldShowEmptyAlbum = true

    // Disable to pick asset
    picker.canPickAsset = { (asset:Asset) -> Bool in
        return false
    }

    // Color
    ColorConfig.backgroundColor = UIColor.white
   }

使用以下函数

    func getAssetThumbnail(asset: PHAsset) -> UIImage {
    let manager = PHImageManager.default()
    let option = PHImageRequestOptions()
    var thumbnail = UIImage()
    option.version = .original
    option.isSynchronous = true
    manager.requestImage(for: asset, targetSize: CGSize(width: 100, height: 100), contentMode: .aspectFit, options: option, resultHandler: {(result, info)->Void in thumbnail = result! })
    return thumbnail
}

让我们把第一个资产作为

    let phAsset = pickedAssts.first