Мне нужен UIImageView на моем CollectionViewCell, чтобы обновить изображение камеры. Используя опцию камеры UIImagePickerController. Я думаю, что все мои выходы и идентификаторы верны. Вот мой UIViewController код:Как использовать изображение камеры UIImagePickerController для обновления моего UICollectionViewCell?
import UIKit
import Photos
class CameraVC: BaseViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate, UICollectionViewDelegateFlowLayout, UICollectionViewDataSource {
@IBOutlet weak var collectionView: UICollectionView!
@IBAction func importImage(_ sender: Any) {
let imagePickerController = UIImagePickerController()
imagePickerController.delegate = self
imagePickerController.sourceType = UIImagePickerControllerSourceType.camera
imagePickerController.allowsEditing = true
self.present(imagePickerController, animated: true) {
//After it is complete
}
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
imageArray.append(image)
}
else {
//Error
}
self.dismiss(animated: true, completion: nil)
getPhotos()
}
var imageArray = [UIImage]()
func getPhotos() {
let imgManager = PHImageManager.default()
let requestOptions = PHImageRequestOptions()
requestOptions.isSynchronous = true
requestOptions.deliveryMode = .highQualityFormat
let fetchOptions = PHFetchOptions()
fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]
if let fecthResult: PHFetchResult = PHAsset.fetchAssets(with: .image, options: fetchOptions) {
if fecthResult.count > 0 {
for i in 0..<fecthResult.count {
imgManager.requestImage(for: fecthResult.object(at: i) as! PHAsset, targetSize: CGSize(width: 200, height: 200), contentMode: .aspectFill, options: requestOptions, resultHandler: {
image, error in
self.imageArray.append(image!)
})
}
}
else {
print("You are without any photos.")
self.collectionView?.reloadData()
}
}
}
override func viewDidLoad() {
super.viewDidLoad()
collectionView.delegate = self
collectionView.dataSource = self
self.addSlideMenuButton()
self.title = "Camera"
getPhotos()
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return imageArray.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath)
let imageView = cell.viewWithTag(1) as! UIImageView
imageView.image = imageArray[indexPath.row]
return cell
}
}
и вот мой UICollectionViewCell код:
import UIKit
class CameraImageCell: UICollectionViewCell {
@IBOutlet weak var thumb: UIImageView!
func configureCell() { }
}
-Спасибо за помощь -