问题描述
我按照这个视频创建了UICollectionViewController,但集合单元没有按预期显示.我添加了一些打印消息,结果是调用了 numberOfItemsInSection,但从未调用过 cellForItemAt 函数.另外,在 viewDidLoad 方法中,我打印了 collectionView?.contentSize 并且它是 (0.0, 0.0).不知道是什么问题.谁能帮忙解释一下?
I followed this video to create the UICollectionViewController, but the collection cells do not appear as expected. I added some print messages, and it turns out that numberOfItemsInSection is called, but cellForItemAt function is never called. Also, in viewDidLoad method, I printed out collectionView?.contentSize and it's (0.0, 0.0). Not sure what's the problem. Can anyone help explain?
更多:我发现问题可能是我没有使用 pushViewController 来导航,而是使用了 performSegue,所以我没有像视频那样设置 UICollectionDelegateFlowLayout...有什么办法可以解决它?
More:I found the problem might be that I didn't use pushViewController to navigate but use performSegue, so I didn't set UICollectionDelegateFlowLayout as the video did... Any way to fix it?
推荐答案
确保你已经设置了你的 UICollectionView 的 Datasource 和 Delegate.
Make sure that you have set Datasource and Delegate of your UICollectionView.
yourcollectionview.delegate = self
yourcollectionview.dataSource = self
这篇关于cellForItemAt 从未在类中调用 extends UICollectionViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!