0
Ich bin mit schnellen 3 und verwende NohanaImagePickerpod Datei mehr Bilder auszuwählen und sein Arbeits gut das Problem ist, dass ich ausgewählt Bilder in der Sammlung Ansicht sehen will, und ich werde in dieser LinieWie kann ich Bilder mit der NohanaImagePicker Pod-Datei sehen?
cell.imageforCV.image = ViewController.imgArray[indexPath.row]
I fatal Fehler erhalten verwendet statische Variante für imgArray
hier ist mein Codes
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
}