Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash on Calling Collection Reload #15

Closed
Hamza123Imran opened this issue Mar 28, 2019 · 1 comment
Closed

Crash on Calling Collection Reload #15

Hamza123Imran opened this issue Mar 28, 2019 · 1 comment

Comments

@Hamza123Imran
Copy link

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?

@filletofish
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants