The Bao
The Bao

Reputation: 129

Collection View inside Table View Cell Slow Scroll Performance

I have checked, tried many solutions on stackoverflow and from many website I searched.

My problem: I have a collection view inside table view cell. My data must be loaded 1 time in table view ( viewdidload).

When I pass data to collection view inside table cells, it's not appear because I need to reload collection view again.

So I do: Data -> inside cellforrow of table view -> Pass to collection view -> cell.collectionView.reloadData()

This cause a problem about scroll performance: collectionView.reloadData() call over and over again when I scroll ( this right because of resuable cells architecture of table view.

Here my code in cellforrow of tableView:

let cell = tableView.dequeueReusableCell(withIdentifier: SubCategoryCellID) as! SubCategoryCell
        if isFetched {
            cell.shimmeringView.isShimmering = false
            cell.shimmeringImageView.isHidden = true
            cell.shimmeringView.isHidden = true
            cell.listLocation = nestedSubLocation[indexPath.item]
            cell.collectionView.reloadData()
        }else {
            return cell
        }

Solutions I tried: + Create static cells and get cells to display in cellForRow (it's totally fix scroll performance but I think it not good for memory management and it's not working if parent is collection view). + Reload data when scroll stop: it's still need to reloadData in loading first time and wrong data if I dont reload again.

To fix that, anyone have an clever approach to fix scroll performance ?

Upvotes: 4

Views: 1898

Answers (1)

Bala
Bala

Reputation: 1304

Put this code after cell.collectionView.reloadData()

cell.collectionView.scrollRectToVisible(CGRect.zero, animated: false)

Upvotes: 1

Related Questions