Crash on Calling Collection Reload
Hamza123Imran opened this issue · comments
Hi , i have used ur library in my collection view, i have mad my custom collection view have a single image on cell. I have passed all the data source and delegate this is my code,
//Collection View Reload self.knowledgeCollectionView.collectionViewLayout = CardsCollectionViewLayout() self.knowledgeCollectionView.isPagingEnabled = true self.knowledgeCollectionView.showsHorizontalScrollIndicator = false self.knowledgeCollectionView.reloadData()
` override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return cardsArray.count
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = knowledgeCollectionView.dequeueReusableCell(withReuseIdentifier: "knowledgeCell", for: indexPath) as! KnowledgeCVC
cell.cardImage.image = cardsArray[indexPath.row]
return cell
}`
But when i call my VC the app crashes on a delegate written in ur library,
` // MARK: - UICollectionViewDelegateFlowLayut
@objc open func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize {
guard let cellWidthValue = cachedCellWidths?[indexPath.row] else {
fatalError("cachedCellWidths for \(indexPath.row) must not be nil")
}
return CGSize(width: cellWidthValue, height: collectionView.frame.size.height)
}`
Error is Thread 1: Fatal error: Index out of range
. How i can get rid of this?
Hi @Hamza123Imran,
Are you sure that you are speaking about the code from my library?
My library only includes CardsCollectionViewLayout.swift
and there are no lines of code that you have mentioned.