представление коллекции, показывающее меньшее количество ячеек в cellForItemAt - PullRequest
3 голосов
/ 21 апреля 2020

У меня есть представление коллекции с массивом из 5 элементов, как показано ниже:

var photos = [String]()
 override func viewDidLoad() {
        super.viewDidLoad()
 self.photos = ["background", "living", "bedroom", "dining","bathroom"]
}

В представлении коллекции

 func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {

        print("total no of photos are",photos.count)
        return photos.count

    }
       func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

        let cell = photocollview.dequeueReusableCell(withReuseIdentifier: "Cell10", for: indexPath) as! PhotoCollectionViewCell


        cell.layer.borderColor = UIColor.black.cgColor
        cell.layer.borderWidth = 1.0


        let str = photos[indexPath.row]

        print("str is",str)

}

Количество элементов в разделе в представлении коллекции показывает 5, но в cellforitemat

строка выводит только 3 значения при печати. ​​

В чем может быть проблема?

1 Ответ

1 голос
/ 21 апреля 2020

позвоните и вернитесь, может быть, это полезно.

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
   let cell = photocollview.dequeueReusableCell(withReuseIdentifier: "Cell10", for: indexPath) as! PhotoCollectionViewCell
   cell.layer.borderColor = UIColor.black.cgColor
   cell.layer.borderWidth = 1.0
   let str = photos[indexPath.row]
   print("str is",str)
   return cell
}
...