gpt4 book ai didi

ios - Collection View 显示 cellForItemAt 中的单元格数量较少

转载 作者:行者123 更新时间:2023-12-01 15:46:47 26 4
gpt4 key购买 nike

我有一个包含 5 个项目的 Collection View ,如下所示:

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

在 Collection View 中

 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)

}

Collection View 中部分中的项目数显示为 5,但在 cellforitemat 中显示

str 在打印时仅显示 3 个值。

可能是什么问题?

最佳答案

调用也返回,也许它有帮助。

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
}

关于ios - Collection View 显示 cellForItemAt 中的单元格数量较少,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61342723/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com