Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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}'

question from:https://stackoverflow.com/questions/65936584/application-crash-in-iphone-6-while-reloaddata

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
123 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

_cell.collectionView.collectionViewLayout.invalidateLayout()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...