I have a viewController
containing segmentedControl
. I have a VCA and VCB which are in the segmentedControl
. When I tap on second segment VCB appears. Now I am pushing another ViewController from VCB. But when coming back from that viewController, viewDidAppear
of VCA is being Called. Which is strange to me. Because user is on the VCB so why the viewWillAppear
and viewDidAppear
of VCA are being called ? Here is a diagram to explain more
This is how I am adding viewControllers to segmentedControl
func switchToViewController(viewController: UIViewController, selectedIndex: Int) {
viewController.removeFromParentViewController()
viewController.view.removeFromSuperview()
addChildViewController(viewController)
viewController.view.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(viewController.view)
// Setting constraints of the container view
NSLayoutConstraint.activate([
viewController.view.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 0),
viewController.view.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: 0),
viewController.view.topAnchor.constraint(equalTo: view.topAnchor, constant: 50),
viewController.view.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 0)
])
viewController.didMove(toParentViewController: self)
}
I am just unable to understand the behavior. So please guide me.