Проблема заключается в том что фотографии не загружаются в ячейку.
Код класса с загрузкой
import Foundation
import UIKit
import FirebaseDatabase
import FirebaseStorage
import FirebaseAuth
import Firebase
struct Celltest {
var name:String
var image:UIImage
}
class MenuCell {
let ref = Database.database().reference().child("Users")
var cells=[Celltest]()
init() {
setUp()
}
func setUp(){
ref.child(Auth.auth().currentUser!.uid).observe(.value) { (snapshot) in
guard let value=snapshot.childSnapshot(forPath: "image").value,snapshot.exists()else{
return
}
let references=Storage.storage().reference(forURL: value as! String)
let megabyte=Int64(1*1024*1024)
references.getData(maxSize: megabyte) { (data,error) in
guard let imageData=data else{
return
}
let image=UIImage(data: imageData)
guard let values=snapshot.childSnapshot(forPath: "name").value,snapshot.exists()else{
return
}
let test=Celltest(name: values as! String, image: image!)
self.cells=[test]
}
}
}
}
Контроллер ячеек
import UIKit
class CollectionViewCell: UICollectionViewCell {
@IBOutlet weak var productImage: UIImageView!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
func sutUpCell(test:Celltest){
self.productImage.image=test.image
}
}
ViewController где находится коллекция
import UIKit
class CollectionViewController: UIViewController {
var menu:MenuCell=MenuCell()
@IBOutlet weak var collectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
self.collectionView.register(UINib(nibName: "CollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "CollectionViewCell")
self.collectionView.dataSource=self
self.collectionView.delegate=self
}
}
extension CollectionViewController:UICollectionViewDataSource,UICollectionViewDelegate{
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return menu.cells.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell=collectionView.dequeueReusableCell(withReuseIdentifier: "CollectionViewCell", for: indexPath) as! CollectionViewCell
let test=menu.cells[indexPath.item]
cell.sutUpCell(test: test)
collectionView.reloadData()
return cell
}
}