I am using the viewForSupplementaryElementOfKind
function to apply the header section from the uicollectionview
controller. However, before the asynchronous parsing of the viewDidAppear
API, the row index is loaded into the viewForSupplementaryElementOfKind
function and becomes out of range. What should I do?
Here is my code...
override func viewDidAppear(_ animated: Bool) {
callVideo3API()
}
override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
switch kind {
case UICollectionElementKindSectionHeader:
let row1 = self.list[0]
let row2 = self.list[1]
let row3 = self.list[2]
let headerSection = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "Header", for: indexPath) as! HeaderSection
headerSection.nameLabel01.text = row1.nickname
headerSection.nameLabel02.text = row2.nickname
headerSection.nameLabel03.text = row3.nickname
return headerSection
default:
assert(false, "Unexpected element kind")
}
}