             
             viewController.willMove(toParentViewController: nil)
             viewController.view.removeFromSuperview()
-            viewController.willMove(toParentViewController: nil)
+            viewController.removeFromParentViewController()
             
             if automaticallyHandleAppearanceTransitions {
                 viewController.endAppearanceTransition()

            self.setNeedsStatusBarAppearanceUpdate()
            
        }, completion: { (finished) -> Void in
            //Call these two methods to notify that two view controllers are already removed or added to container view controller (Check Documentation)
            oldViewController.removeFromParentViewController()
            
            if self.automaticallyHandleAppearanceTransitions {
                oldViewController.didMove(toParentViewController: nil)
                newViewController.didMove(toParentViewController: self)
                
                oldViewController.endAppearanceTransition()

        
        // Then add subview, we do this later to prevent viewDidLoad of child view controllers to be called before page segment is allocated.
        for (index, viewController) in viewControllers.enumerated() {
            // Add view controller's view if it must be visible in scroll view
            if let _ = indexes.index(of: index) {
                // Add to call viewDidLoad if needed
                viewController.view.frame = CGRect(x: CGFloat(index) * view.bounds.width, y: 0, width: view.bounds.width, height: view.bounds.height - segmentedControlHeight)
                pageScrollView.addSubview(viewController.view)
                
                // This will call viewWillAppear
                addChildViewController(viewController)
                
                // This will call viewDidAppear
                viewController.didMove(toParentViewController: self)
            }
        }
