【问题标题】:Multiple UICollectionViews in ViewController | Would not call one CollectionViews Delegate methodsViewController 中的多个 UICollectionViews |不会调用一个 CollectionViews 委托方法
【发布时间】: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
        }

    }

而 UICollectionView 的连接方式如下:

和:

请帮忙。非常感谢

【问题讨论】:

  • 移除工作集合视图的委托连接并检查是否为variantsCollectionView执行了数据源方法。
  • 如果他们这样做了,那么if collectionView == self.variantsCollectionView { 不起作用。在这种情况下,请检查 variantsCollectionView 的 IBOutlet 是否连接正确。
  • @Evgeniy 不,他们现在没有被要求为工作集合工作,他们也没有为另一个人工作
  • 在 viewDidLoad() 中检查集合的 dataSource 不是 nil。
  • 然后检查cellSizeForItem,它一定是0,0。

标签: ios xcode uicollectionview storyboard swift4


【解决方案1】:

通过 cmets TS 找到解决方案,步骤如下:

  1. 确保两个集合视图都具有非零数据源(和委托)。
  2. 检查是否为两个集合视图执行了数据源方法。
  3. 检查两个集合视图的单元格大小是否有效。

在查看stack view中每个collection view的高度后,终于发现了问题。

基本上 CollectionView 有一个特定的高度,而 VariantCollectionView 没有,两者都在 stackView 中。当第一次 是在视图中创建的,它占据了整个大小,而另一个 一种实际上消失了。因此问题。

【讨论】:

    猜你喜欢
    • 2018-04-27
    • 2017-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多