从 table 视图中的集合视图执行 segue

perform segue from collection view inside table view

我的第二个单元格中有一个带有集合视图的 table 视图。

单击集合视图中的视频时,我想执行到另一个视图控制器的 segue。

这是示例代码。

class tableViewClass: UIViewController, UITableViewDelegate, UITableViewDataSource, VideoCellSelectionDelegate {
    @IBOutlet weak var tableView: UITableView!

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 1
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "VideoCell", for: indexPath) as! VideoCell
        cell.delegate = self
        return cell
    }

    func didSelect() {
        //performSegue
    }

}

VideoCell 必须有一个在 collectionView 单元格为 select

时调用的委托
protocol VideoCellSelectionDelegate {
    func didSelect()
}

class VideoCell: UITableViewCell, UICollectionViewDelegate {
    var delegate: VideoCellSelectionDelegate?

    @IBOutlet weak var collectionView: UICollectionView!

    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        delegate?.didSelect()
    }

}