gpt4 book ai didi

ios - 当 UICollectionView 背景为 UICollectionView 单元格时,不显示 UICollectionView 单元格

转载 作者:行者123 更新时间:2023-11-30 12:42:38 26 4
gpt4 key购买 nike

这是我的 ImageController 类(一个 ViewController)仅显示 Collection View 的背景,而其中的单元格则不显示。有什么帮助吗?是不是我没有正确初始化什么?

这是类(class):

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
}

}

最佳答案

您应该在viewDidLoad()中添加:

collectionView.delegate = self
collectionView.dataSource = self

此外,尝试调试方法(添加断点并检查它们是否可达)。

希望这有帮助。

关于ios - 当 UICollectionView 背景为 UICollectionView 单元格时,不显示 UICollectionView 单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42056701/

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