我正在尝试模仿 google places 底部滚动列表。请引用下面的图片以便更好地理解
我创建了一个水平滚动的 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/