0
我正在使用viewForSupplementaryElementOfKind
函數來應用uicollectionview
控制器中的標題部分。但是,在對viewDidAppear
API進行異步解析之前,行索引會加載到viewForSupplementaryElementOfKind
函數中並且超出範圍。我該怎麼辦?uicollectionview控制器中的標題部分。超出範圍
這裏是我的代碼...
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")
}
}
它來了,因爲數據源可能是空的。所以,你必須在獲取數據源後重新加載'collectionView'。併發布你的'numberOfSectionsInCollectionView'和'numberOfItemsInSection'方法。 –