Skip to content

Instantly share code, notes, and snippets.

@candostdagdeviren
Created December 3, 2020 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save candostdagdeviren/9d5eb96712d4ab99fa6286c797aead84 to your computer and use it in GitHub Desktop.
Save candostdagdeviren/9d5eb96712d4ab99fa6286c797aead84 to your computer and use it in GitHub Desktop.
// Adding a view controller to another
let childViewController = UIViewController()
let parentViewController = UIViewController()
parentViewController.addChild(childViewController)
parentViewController.view.addSubview(childViewController.view)
// setup auto-layout constraints for childViewController.view
childViewController.didMove(toParent: parentViewController)
// Removing the child view controller from parent
childViewController.willMove(toParent: nil)
childViewController.view.removeFromSuperview()
childViewController.removeFromParent()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment