代码之家  ›  专栏  ›  技术社区  ›  Mohsin Khubaib Ahmed

ViewController中的多个UICollectionView不调用一个CollectionView委托方法

  •  0
  • Mohsin Khubaib Ahmed  · 技术社区  · 6 年前

    因此,我在我的故事板中有两个 uiCollectionView uiviewController uiCollectionView,并且这两个都与委托和数据源链接到我的viewController。所有相关联的 uiCollectionView delegate方法都已实现,并检查是否已实现 uiCollectionView 但令人沮丧的是,一个 uicollectionview 正在得到满足,而另一个则被完全忽略。我在所有方面都有点头疼,但这让我更接近边缘,请帮忙。

    func collectionview(u collectionview:uicollectionview,numberofitemsinsection-section:int)->int{
    如果collectionview==self.variantscollectionview{
    //让count=(item?.变量组?伯爵!
    返回1
    }否则{
    返回2//(项?外组?伯爵!
    }
    }
    < /代码> 
    
    

    func collectionview(u collectionview:uicollectionview,cellforitemat indexpath:indexpath)->uicollectionviewscell{
    
    如果collectionview==self.variantscollectionview{
    //它根本就不在这里
    让cell=collectionview.dequeuerusablecell(使用reuseIdentifier:“cell_variant”,用于:indexpath)
    返回单元格
    
    }否则{
    让cell=collectionview.dequeuerusablecell(使用ReuseIdentifier:“cell”,用于:indexPath)
    //这里总是针对单元格的数量
    
    返回单元
    }
    
    }
    < /代码> 
    
    

    而uiCollection视图是这样连接的:

    请帮忙。非常感谢控制器。所有相关联的UICollectionView实现委托方法并检查ui集合视图执行。但这真让人沮丧ui集合视图正在被迎合,而另一个却被完全忽视了。我在所有方面都有点头疼,但这让我更接近边缘,请帮忙。

    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
            }
    
        }
    

    而uiCollection视图是这样连接的: enter image description here

    还有: enter image description here

    请帮忙。非常感谢

    1 回复  |  直到 6 年前
        1
  •  1
  •   Yevgeniy Leychenko    6 年前

    通过注释,TS通过以下步骤找到了解决方案:

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

    最后,通过检查堆栈视图中每个集合视图的高度发现了问题。

    基本上,CollectionView具有特定的高度,而 VariantCollectionView没有,两者都在StackView中。什么时候开始 是在视图中创建的,它占用了整个大小 有点消失了。这就是问题所在。