Instantly share code, notes, and snippets.

Embed
What would you like to do?
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