1
votes

I am trying to mimic google places bottom scrolling list. Please refer the images below for better understanding

Google Places Bottom Scrolling List UI Google Places Bottom Scrolling List UI

My UI My UI

I have created a horizontal scrolling UICollectionView, with each UICollectionViewCell containing a UITableView

I have an array that contains data related to each tableview. I am loading the data into the tableView during UICollectionViewDelegate Method [cellForRow at: indexPath:] by using indexPath.row as my arrayIndex. But I see some tableViews have same data.

I would like to know how do I keep track of each UICollectionViewCell and load only related data into that tableView inside UICollectionViewCell.

1

1 Answers

0
votes

Make sure you don't use collectionView prefetching.

if (collectionView.responds(to: #selector(setter:
UICollectionView.isPrefetchingEnabled))) {

    collectionView.isPrefetchingEnabled = false

}

I suggest you do not reuse tableViews.

func collectionView(_ collectionView: UICollectionView,
cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

    let cell = collectionView.dequeueReusableCell(withReuseIdentifier:
"YourCellIdentifier", for: indexPath)

    let tableView = tableViews[indexPath.item]
    tableView.data = dataArray[indexPath.item];

    tableView.removeFromSuperview()
    cell.contentView .addSubview(tableView)
    tableView.frame = cell.contentView.bounds

    return cell

}