Заполните textLabel collectionView данными Firebase - PullRequest
0 голосов
/ 07 апреля 2020

У меня есть такая структура:

struct Item {
    var name : String
    var description : String
    var price : Int
}

, и я заполнил это наблюдением Firebase. Затем я объявил переменную:

var items: [Item] = []

и, если я распечатал эту переменную, я увидел, что все работает в моей консоли. Но я хочу заполнить CollectionViewCell UILabel каждым элементом в массиве, и я написал это, но все еще не работает:

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cella", for: indexPath) as! CollectionViewCell
    let singleItem = self.items[indexPath.row]
    cell.nameItem.text = singleItem.name 
    return cell
}

Я думаю, что ошибка в indexPath.row.

...