UITollectionView在UITableViewCell里面

问题描述 投票:0回答:1

我想在我的viewcontroller中实现一个包含UITableView的函数,而TableViewCell包含一个CollectionView

我想用用户按下的所选CollectionViewCell启动一个函数,但我无法弄清楚如何区分用户选择的单元格,

现在我用我的prepareForSegue

  override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    switch segue.identifier {
    case "SelectedDish"?:
        let myVC = segue.destination as! SelectedDishViewController
          if let indexPath = my_table_view.indexPathForSelectedRow . // this will tell me what cell in the table view the user chose a collectionViewcell
          {
 // here I want to get the index of the collectionViewCell inside the tableview.

    default:
        break
    }
}

有没有不同的方式实现这一目标?

ios swift uitableview uicollectionview
1个回答
0
投票

我设法解决了我的问题,

我在我的collecitonview中的每个单元格中隐藏了一个按钮,每个单元格都有一个分区编号,即tableview单元格indexpath.row,我为每个集合视图单元格分配一个索引,我按下按钮时设置每个单元格,我存储了集合视图单元格的部分和索引,然后我在准备segue时使用它。

© www.soinside.com 2019 - 2024. All rights reserved.