首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CollectionView多个SectionsHeader行

CollectionView多个SectionsHeader行
EN

Stack Overflow用户
提问于 2020-04-11 01:21:29
回答 1查看 25关注 0票数 0

我在这个TableView中有一个collectionView。我在CollectionView中添加了sectionHeader,但相同的名称显示在两行中。我确实切换了大小写,但总是大小写0工作,大小写1不工作。如何使用两个不同的SectionHeader?第一部分0.row第二部分1.row我希望行的sectionHeaders是分开的。

Col Rows

代码语言:javascript
复制
extension denemeView: UICollectionViewDelegate, UICollectionViewDataSource,  UICollectionViewDelegateFlowLayout{
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {

        return model[collectionView.tag].count

    }

  func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
   if (collectionView == collectionViewSıralama) {

           var reusableview = UICollectionReusableView()
            if (kind == UICollectionView.elementKindSectionHeader) {
                let section = indexPath[indexPath.row]
               switch (section) {
               case 0:
                   if let sectionHeader = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "SectionHeader", for: indexPath) as? SectionHeader{
                                      let KatIsım : String = davetiyeKatIsım[collectionView.tag]

                                                                sectionHeader.sectionHeaderlabel.text = KatIsım


          let layout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout
                                                                layout?.sectionHeadersPinToVisibleBounds = true

                                                                            sectionHeader.sectionHeaderlabel.text = KatIsım
                                      reusableview = sectionHeader
                                                        }
               case 1:
                   if let sectionHeader = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "SectionHeader", for: indexPath) as? SectionHeader{
                                      let layout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout
                                                                layout?.sectionHeadersPinToVisibleBounds = true
                  let KatIsım : String = "davetiyeKatIsım2[0]"
                   sectionHeader.sectionHeaderlabel.text = KatIsım

                                  reusableview = sectionHeader
                                                    }
               default:
                   return reusableview

               }
           }
           return reusableview
        }
        return UICollectionReusableView()
    }
EN

回答 1

Stack Overflow用户

发布于 2020-04-11 03:16:37

您没有提供UICollectionViewDelegate方法的实现,从而导致节的数量始终为1 (如果您不覆盖该函数,这是默认数量),因此您的开关始终为数字1。

因此,重写方法func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int,它应该可以工作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61145367

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档