我在这个TableView中有一个collectionView。我在CollectionView中添加了sectionHeader,但相同的名称显示在两行中。我确实切换了大小写,但总是大小写0工作,大小写1不工作。如何使用两个不同的SectionHeader?第一部分0.row第二部分1.row我希望行的sectionHeaders是分开的。
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()
}发布于 2020-04-11 03:16:37
您没有提供UICollectionViewDelegate方法的实现,从而导致节的数量始终为1 (如果您不覆盖该函数,这是默认数量),因此您的开关始终为数字1。
因此,重写方法func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int,它应该可以工作。
https://stackoverflow.com/questions/61145367
复制相似问题