Skip to content

Instantly share code, notes, and snippets.

@candostdagdeviren
Created November 18, 2018 11:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save candostdagdeviren/cf2a84ec4368864d2a45567995d8bad1 to your computer and use it in GitHub Desktop.
Save candostdagdeviren/cf2a84ec4368864d2a45567995d8bad1 to your computer and use it in GitHub Desktop.
View Lifecycle - NS for iOS Devs
// 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