iosswiftuicollectionviewuicontainerview

Present view controller in a container view at collection view didSelectItemAtIndexPath swift


I am trying to present a view controller in a container view when i select a cell from a collection view. The problem is that I can't seem to understand how to present it in the container below the collection view. enter image description here

I tried:

if (indexPath.row == 0){

                // Presenting first view controller

    let detailedViewController: ViewController =
          self.storyboard!.instantiateViewControllerWithIdentifier("ViewController") as! ViewController

                self.presentViewController(detailedViewController, animated: true, completion: nil)

How can I make it go to the container instead of presenting the whole view controller. Thanks in advance!


Solution

  • self.addChildViewController(detailedViewController)
    containerView.addSubview(detailedViewController.view)