ViewController 中的多个 UICollectionView |不会调用一个 CollectionViews 委托方法
Multiple UICollectionViews in ViewController | Would not call one CollectionViews Delegate methods
所以我在 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
}
}
而 UICollectionViews 是这样连接的:
和:
请帮忙。非常感谢
通过评论,TS 通过以下步骤找到了解决方案:
- 确保两个集合视图都有非零数据源(和委托)。
- 检查是否为两个集合视图执行了数据源方法。
- 检查两个集合视图的单元格大小是否有效。
在检查stack view中每个collection view的高度后,终于找到了问题。
basically CollectionView has a specific height whereas
VariantCollectionView didnt, and both were in a stackView. When first
was created in view it took up the entire size where as the other one
kind of actually disappeared. Hence the issue.
所以我在 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
}
}
而 UICollectionViews 是这样连接的:
和:
请帮忙。非常感谢
通过评论,TS 通过以下步骤找到了解决方案:
- 确保两个集合视图都有非零数据源(和委托)。
- 检查是否为两个集合视图执行了数据源方法。
- 检查两个集合视图的单元格大小是否有效。
在检查stack view中每个collection view的高度后,终于找到了问题。
basically CollectionView has a specific height whereas VariantCollectionView didnt, and both were in a stackView. When first was created in view it took up the entire size where as the other one kind of actually disappeared. Hence the issue.