Mudasir Syed
Mudasir Syed

Reputation: 131

Application crash in IPhone 6 while reloadData

I'm using collection view in side UITableViewCell, on reload

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        guard let _cell = cell as? BrandRow else { return }

        let _flow = columnLayout
        _flow.scrollDirection = .horizontal

        _cell.collectionView.collectionViewLayout = _flow
        _cell.collectionView.delegate = self
        _cell.collectionView.tag = indexPath.section
        _cell.collectionView.dataSource = self
        _cell.collectionView.showsVerticalScrollIndicator = false
        _cell.collectionView.showsHorizontalScrollIndicator = false
        _cell.collectionView.reloadData()

    }

In iPhone 6 while cell get reused it crashes my app

_cell.collectionView.reloadData()

can anyone please let me know what's wrong with my code?

Error

Assertion failure in -[UICollectionViewData validateLayoutInRect:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKitCore/UIKit-3698.140/UICollectionViewData.m:447

2021-01-28 17:10:08.921104+0500 Okayhai[630:48362] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UICollectionView received layout attributes for a cell with an index path that does not exist: <NSIndexPath: 0xec57a98e0a4dfaae> {length = 2, path = 0 - 4}'

Upvotes: 0

Views: 79

Answers (1)

stackich
stackich

Reputation: 5217

try this:
below _cell.collectionView.reloadData()
put

_cell.collectionView.collectionViewLayout.invalidateLayout()

Upvotes: 0

Related Questions