【发布时间】:2019-04-26 03:01:08
【问题描述】:
所以我在 Storyboard 中的 UIViewController 中有两个 UICollectionViews,它们都通过委托和数据源链接到我的 ViewController。所有关联的UICollectionView 委托方法都已实现,并且UICollectionViews 的检查已实现。但令人沮丧的是,一个UICollectionView 得到了满足,而另一个却被完全忽略了。我在所有可用方面都摸不着头脑,但这有点让我更接近边缘,请帮忙。
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if collectionView == self.variantsCollectionView {
// let count = (item?.variant_groups?.count)!
return 1
} else {
return 2//(item?.extra_groups?.count)!
}
}
和
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell{
if collectionView == self.variantsCollectionView {
//IT DOESNT EVEN COME HERE AT ALL
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell_variant", for: indexPath)
return cell
} else {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath)
//HERE IT COMES ALWAYS FOR THE NUMBER OF CELLS
return cell
}
}
请帮忙。非常感谢
【问题讨论】:
-
移除工作集合视图的委托连接并检查是否为
variantsCollectionView执行了数据源方法。 -
如果他们这样做了,那么
if collectionView == self.variantsCollectionView {不起作用。在这种情况下,请检查variantsCollectionView的 IBOutlet 是否连接正确。 -
@Evgeniy 不,他们现在没有被要求为工作集合工作,他们也没有为另一个人工作
-
在 viewDidLoad() 中检查集合的 dataSource 不是 nil。
-
然后检查cellSizeForItem,它一定是0,0。
标签: ios xcode uicollectionview storyboard swift4