I am trying to learn how to use collections views and what I want to do is be able to access the photos in the photo library and put them in a collection view .
The problem i’m having is getting the photos to show up in the cell when I click them nothing shoes up in the cell. I’ not sure what I’m doing wrong. I’m pretty sure i’m missing something but I don’t know what."
import UIKit
import Photos
class ViewController: UIViewController , UICollectionViewDelegate , UICollectionViewDataSource , UICollectionViewDelegateFlowLayout , UIImagePickerControllerDelegate , UINavigationControllerDelegate
{
@IBOutlet weak var collectionView: UICollectionView!
@IBAction func addPhoto(_ sender: AnyObject) {
let picker:UIImagePickerController = UIImagePickerController()
picker.sourceType = .photoLibrary
picker.mediaTypes = UIImagePickerController.availableMediaTypes(for: .photoLibrary)!
picker.delegate = self
picker.allowsEditing = false
self.present(picker, animated: true, completion: nil)
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell: ImageCollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! ImageCollectionViewCell
return cell
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 3
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let pickedimage = (info[UIImagePickerControllerOriginalImage] as? UIImage){
}
dismiss(animated: true, completion: nil)
}
Collectionview cell
import UIKit
class ImageCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var imageView: UIImageView!
func configurecell(image: UIImage){
imageView.image = image
}
}