I'm using viewForSupplementaryElementOfKind
to generate a header in my Collection View.
The header (SectionHeader
) is a Section Header accessory in Storyboard that simply just contains 1 outlet.
class SectionHeader: UICollectionReusableView {
@IBOutlet weak var sectionHeaderlabel: UILabel!
}
Here's my implementation of viewForSupplementaryElementOfKind
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind:
String, at indexPath: IndexPath) -> UICollectionReusableView {
print("SECTION TITLE (brand of bindings) --------> \(sectionTitle)")
if let sectionHeader = allCollectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "bindingsID", for: indexPath) as? SectionHeader{
sectionHeader.sectionHeaderlabel.text = "Select \(sectionTitle)"
return sectionHeader
}
return UICollectionReusableView()
}
sectionTitle gets set via segue.
The problem is when this View Controller loads, the title reads "Select "
When I scroll the header off the screen, and then back on the screen, the title properly displays: "Select Burton Bindings"
I tested sectionTitle
in viewWillAppear, and the correct data printed.
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
print("viewWillAppear ----- \(sectionTitle)")
}
(printed viewWillAppear ----- Burton Bindings
)
I suppose my issue is due to the lifecycle of viewForSupplementaryElementOfKind, and when it is being called?
How can I get the section title to display when the VC loads, instead of having to scroll the header off and on the screen in order for it to display?