Это мой класс для ImageController (ViewController) Пока отображается только фон представления коллекции, в то время как в нем нет ячеек. Любая помощь? Есть ли что-то, что я не инициализировал правильно?Ячейки UICollectionView не отображаются, когда UICollectionView background is
Вот класс:
class ImageController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {
let reuseIdentifier = "imageCell"
@IBOutlet weak var collectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 10
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath as IndexPath) as! ImageCell
cell.myImage.image = unknown //name of image, isn't the cause of error
return cell
}
}
Вы фактически назначили делегата и источник данных? Я вижу, что вы настроены на VC, чтобы соответствовать обоим, но вам все равно нужно сказать 'collectionView.delegate = self' и' collectionView.dataSource = self' – Pierce