Swift3 如何从UICollectiveViewCell类显示视图控制器-SWIFT

Swift3 如何从UICollectiveViewCell类显示视图控制器-SWIFT,swift3,uinavigationcontroller,viewcontroller,Swift3,Uinavigationcontroller,Viewcontroller,我想知道如何从“didSelectItemAt-Method”展示一个新的视图控制器 请注意,UIViewController不是子类,因此我无权访问navigationController来显示视图控制器 class FeedCell: UICollectionViewCell, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout { let cellId =

我想知道如何从“didSelectItemAt-Method”展示一个新的视图控制器

请注意,UIViewController不是子类,因此我无权访问navigationController来显示视图控制器

class FeedCell: UICollectionViewCell, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {

    let cellId = "cellId"

    lazy var collectionView: UICollectionView = {
        let layout = UICollectionViewFlowLayout()
        let cv = UICollectionView(frame: .zero, collectionViewLayout: layout)
        cv.backgroundColor = UIColor.white
        cv.alwaysBounceVertical = true // Making the collection view scrollable vertically
        cv.dataSource = self
        cv.delegate = self
        return cv

    }()
    override func setupViews(){
        super.setupViews()
        addSubview(collectionView)
        addConstraintWithFormat(format: "H:|[v0]|", views: collectionView)
        addConstraintWithFormat(format: "V:|[v0]|", views: collectionView)
        collectionView.contentInset = UIEdgeInsetsMake(0, 0, 50, 0)


    }

    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 1
    }

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        return collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath)
    }

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
        return 0
    }

    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {




    }




}

首先为viewcontroller提供情节提要id,然后

让destination=UIStoryboard(名称:“故事板”,捆绑包:nil)。实例化视图控制器(标识符为:“您的视图控制器”\u id)
当前(目标,动画:false,完成:nil)

您必须为此实现自定义委托。当用户从集合视图中选择项时,必须使用委托调用父视图方法


以下是对此的参考:

我没有使用故事板构建应用程序。所有操作都是在没有故事板的情况下完成的,所以这种方法仍然可行吗?这将导致应用程序终止,出现以下异常:“应用程序试图在自身上呈现模态视图控制器。”谢谢。这种方法虽然花了一些时间才弄清楚,但效果很好。