gpt4 book ai didi

ios - Collection View 单元格未出现

转载 作者:IT王子 更新时间:2023-10-29 05:20:48 26 4
gpt4 key购买 nike

我想显示与 buttons 一样多的 collectionViewCells,因为我的数组中有字符串。但是当我启动模拟器时,只有 CollectionView 的背景,但没有显示任何单元格。可能是什么错误?

这是我的 CollectionViewController 中的代码,我附加到 main.storyboard 中的 CollectionView:

class CollectionViewController: UICollectionViewController {

var Array = [String]()

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

Array = ["1","2","3","4","5"]
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

func collectionView(collectionView: UICollectionView, numberOfItemsSection section: Int) -> Int {
return Array.count
}

override func
collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

var cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! UICollectionViewCell

var button = cell.viewWithTag(1) as! UIButton
button.titleLabel?.text = Array[indexPath.row]

return cell
}

这些是 Collection View Controller 的连接:

connections

Storyboard上的 View Controller :

viewcontroller

最佳答案

您是否将 CollectionViewController 设置为 Storyboard身份检查器? :)

viewDidLoad 方法中更改数据后,我会尝试调用 reloadData()

希望对你有帮助

关于ios - Collection View 单元格未出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33881683/

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