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

标签 ios swift uitableview uicollectionviewcell

我正在尝试模仿 google places 底部滚动列表。请引用下面的图片以便更好地理解

Google Places 底部滚动列表 UI Google Places Bottom Scrolling List UI

我的界面 My UI

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

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

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

最佳答案

确保您不使用 collectionView 预取。

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

    collectionView.isPrefetchingEnabled = false

}

我建议您不要重复使用 tableView。

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

} 

关于ios - 在 UICollectionViewCell 中使用 UITableView(模仿 Google Places 底部滚动列表),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46311348/

相关文章:

ios - 通过 iOS 上的 <input type=file> 上传存储在云服务上的 0 字节文件

ios - UIViewController 中的 Collection View 可选展开崩溃

ios - 使用 Storyboard时如何在 IB 中为 UITableView 添加页脚 View ?

iOS 调整 UITableheaderView 的大小

ios - 向 AppDelegate 发送消息不适用于应用内购买

ios - 在 Objective-C 的 JSON 中解析 JSON

ios - 如何在按钮函数中传递特定函数的常量值以将其用作导航目的地

swift - 使用 ObjectMapper 时调用中的参数标签不正确

swift - 在小数点分隔符前后都打印 Double 和两位数字

iPhone - 什么是重用标识符(UITableViewCell)?