gpt4 book ai didi

ios - UICollectionView 不要求从 UICollectionViewDataSource 获取数据

转载 作者:行者123 更新时间:2023-11-28 06:18:52 25 4
gpt4 key购买 nike

我已经将自定义数据源设置为 UICollectionView:

let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
let dataSource = DataSource(storage)
let delegate = DelegateFlow()
layout.itemSize = CGSize(width: 90, height: 120)

paymentsHistory = UICollectionView(frame: CGRect.zero, collectionViewLayout: layout)
paymentsHistory.delegate = delegate
paymentsHistory.dataSource = dataSource
paymentsHistory.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "Cell")

self.view.addSubview(paymentsHistory)

Collection View 本身显示正确,但没有出现任何单元格。

我可以从调试输出中看到,

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

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

永远不会被调用。这是为什么?

最佳答案

我的猜测是它被取消引用了,因为 UICollectionView 中的 delegatedatasource 是弱引用。

weak open var delegate: UICollectionViewDelegate?
weak open var dataSource: UICollectionViewDataSource?

一旦你超出了你所在的任何函数的范围,它就应该设为 nil。

如果您将它作为您类(class)的属性(property),它应该可以工作。

关于ios - UICollectionView 不要求从 UICollectionViewDataSource 获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44288765/

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