繁体   English   中英

在UICollectionViewCell中使用UITableView(模仿Google Places底部滚动列表)

[英]Working with UITableView inside UICollectionViewCell(Mimic Google Places Bottom Scrolling List)

我试图模仿谷歌的地方底部滚动列表。 请参考下面的图片以获得更好的理解

Google Places底部滚动列表用户界面 Google Places底部滚动列表用户界面

我的UI 我的UI

我创建了一个水平滚动的UICollectionView,每个UICollectionViewCell都包含一个UITableView

我有一个数组,其中包含与每个tableview相关的数据。 我通过使用indexPath.row作为我的arrayIndex,在UICollectionViewDelegate方法[cellForRow at:indexPath:]期间将数据加载到tableView中。 但是我看到一些tableViews具有相同的数据。

我想知道如何跟踪每个UICollectionViewCell并将仅相关数据加载到UICollectionViewCell内的该tableView中。

确保您不使用collectionView预取。

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

    collectionView.isPrefetchingEnabled = false

}

我建议您不要重用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

} 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM