Swift3 tableview单元格中的Collectionview

Swift3 tableview单元格中的Collectionview,swift3,Swift3,我现在已经在tableview单元格中获取了集合视图,当我单击集合视图单元格时,它将转到下一个视图控制器,是否可能?我曾经尝试过did select item方法,因为如何使用perform segue方法 class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { @IBOutlet weak var tableView: UITableView!

我现在已经在tableview单元格中获取了集合视图,当我单击集合视图单元格时,它将转到下一个视图控制器,是否可能?我曾经尝试过did select item方法,因为如何使用perform segue方法

     class ViewController: UIViewController, UITableViewDelegate,
     UITableViewDataSource {
         @IBOutlet weak var tableView: UITableView!  
    override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
        return false
    }
 }
此ViewController包含Tableview数据源n个委托。其类型为DemoTableViewCell的单元格如下所示

    class DemoTableViewCell: UITableViewCell, UICollectionViewDataSource, UICollectionViewDelegate {
        var parentVC: UIViewController?

        @IBOutlet weak var collectionView: UICollectionView!
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int{
        return 10
    }
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell{
        let demoCollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "DemoCollectionViewCell", for: indexPath) as! DemoCollectionViewCell
        return demoCollectionViewCell
    }

    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath){
        (self.parentVC as! ViewController).performSegue(withIdentifier: "YourSegueName", sender: self)


    }
    }
同样,DemobileViewCell包含集合视图的datasouce和委托,如上所示 此外,didSelectItemAt还包含performSegue,它对Segue使用父引用

现在在集合视图单元格中,有一个名为parentVC的变量,您必须在ViewController类中定义的CellForRowatineXpath中设置该值,如下所示

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
       let demoTableViewCell = tableView.dequeueReusableCell(withIdentifier: "DemoTableViewCell", for: indexPath) as! DemoTableViewCell
        demoTableViewCell.parentVC = self
        demoTableViewCell.collectionView.reloadData()
        return demoTableViewCell
    }

最后从故事板上的collectionViewCell到控制器进行一个分段

我需要在tableview单元格的第一部分中使用collectionview,而remaing没有collectionview,当单击它执行的第二部分tableview单元格准备分段时,现在我的问题是您编写的应该执行的是false,如果我们给出false,tableview会执行prepare for segue方法吗?在这种情况下,当您单击任何类似self的表格单元格时,您需要调用performSegue方法。performSegue(带有标识符:“您的segue\u标识符”,发件人:self)和shouldPerformSegue将仍然返回false。谢谢您的回答。我有一个类似的问题,我解决了。我认为这个答案的关键部分是设置
var parentVC:UIViewController?
内部视图,并通过
demobileviewcell.parentVC=self
cellForRowAt
设置控制器。