ios - CollectionViewCells 中的重复表视图
问题描述
我每个都有水平 CollectionView 和 TableView
问题
表视图重复
代码
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: OrdersCollectionViewCell.id, for: indexPath) as! OrdersCollectionViewCell
switch indexPath.row{
case 0:
cell.backgroundColor = .red
cell.setupTableview()
cell.tableView.backgroundColor = .red
case 1:
cell.backgroundColor = .green
case 2:
cell.backgroundColor = .blue
case 3:
cell.backgroundColor = .orange
case 4:
cell.backgroundColor = .yellow
default:
break
}
return cell
}
setupTableview()
-> 只是委托和数据源
解决方案
请试试这个:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: OrdersCollectionViewCell.id, for: indexPath) as! OrdersCollectionViewCell
switch indexPath.row{
case 0:
cell.backgroundColor = .red
cell.setupTableview()
cell.tableView.backgroundColor = .red
case 1:
cell.backgroundColor = .green
case 2:
cell.backgroundColor = .blue
case 3:
cell.backgroundColor = .orange
case 4:
cell.backgroundColor = .yellow
default:
break
}
cell.tableView.reloadData()
return cell
}
它可能会帮助你。谢谢你。
推荐阅读
- java - 使用 Gradle 创建模块化 SpringBoot 应用
- c# - 在其他计算机上运行 WPF 应用程序时出错
- vue.js - Vue3:当我将安装命令与创建命令分开时数据未定义
- android-studio - 应用程序在单击按钮时崩溃,本应立即发送呼叫
- winapi - 有什么方法可以拦截来自 Windows 应用程序的 I/O 操作,以便我可以在不同的应用程序中实时获取数据
- reactjs - 反应路由器父布局呈现
- javascript - 在 ReactJS 中,从父组件切换子组件中的图像
- flutter - Flutter/Dart - 获取文本输入以显示在着陆/主页脚手架上
- unity3d - Unity VRTK4 Snap Zone,如何设置初始或默认对象?
- javascript - 如何让它等到用户输入日期然后关闭对话框并将值写入其目的地?