viewForSupplementaryElementOfKind is not getting c

2020-04-23 06:58发布

问题:

i have declared collection view like below

lazy var collectionView:UICollectionView = {
        let layout = UICollectionViewFlowLayout()
        layout.itemSize  = UICollectionViewFlowLayout.automaticSize
        layout.minimumLineSpacing = 52
        layout.sectionInset = UIEdgeInsets(top: 25, left: 0, bottom: 30, right: 0)
        var collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
        collectionView.backgroundColor = UIColor.white
        collectionView.showsVerticalScrollIndicator = false
        collectionView.register(XXXCollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)
        collectionView.register(XXXHeaderViewCell.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: headerIdentifier)
        collectionView.delegate = self
        return collectionView
    }()

and implemented below delegates , control comes only to referenceSizeForHeaderInSection method but not to viewForSupplementaryElementOfKind

 public func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
        let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: headerIdentifier, for: indexPath)
        return headerView
    }

public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
        let size = CGSize(width: self.collectionView.bounds.width, height: 200)
        return size
    }

Any help is really appreciated.