【发布时间】:2019-01-15 12:48:09
【问题描述】:
我有水平的 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() -> 只是委托和数据源
【问题讨论】:
-
您必须在
cellForItemAt方法中重新加载您的表格视图,因为它重用了单元格。当您只为第一个单元格设置表格时,还要为其余单元格调用删除表格方法。 -
什么是
setupTableView()?将此方法的代码添加到您的问题中
标签: ios swift uitableview uicollectionview