首页 > 解决方案 > Tableview里面的TableView ios

问题描述

我在 tableview 单元格中使用 tableview。我的主 tableview 使用 Array1 来制作行数,并且在每一行内都有另一个 tableview。现在我有两个不同的数组 Array2 和 Array3。

如何从 Array2 为主 tableview cell0 填充数据,并从 Array3 为主 tableview cell1 填充数据?

标签: swiftiphoneuitableview

解决方案


假设tableView1的第一个单元格是Cell1,第二个单元格是Cell2

Cell1 有 tableView2 和 Cell2 有 tableView3

1)在tableView1的cellForRowAt中,重新加载它包含的子表。

   if indexPath.row == 0 {
         let  cell1 = tableView.dequeueReusableCell(withIdentifier: 
         “Cell1”,for: indexPath) as! Cell1
          -----
        //your code
          -----
         cell1.tableView2.reloadData()
         return cell1
    } else {
         let  cell2 = tableView.dequeueReusableCell(withIdentifier: “Cell2”, 
         for: indexPath) as! Cell2
          -----
        //your code
          -----
         cell2.tableView3.reloadData()
         return cell2

    }

2) 在 Cell1 和 Cell2 中实现各自的 DataSource 和委托。


推荐阅读